Skip to content

Commit

Permalink
refactor: prevent renderDropZone from being redefined on each render
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Jan 13, 2025
1 parent 8b4a0db commit 63b8b9a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/core/components/DropZone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type DropZoneDndData = {
isDroppableTarget: boolean;
};

const DropZoneEditPure = (props: DropZoneProps) => <DropZoneEdit {...props} />;

const DropZoneEdit = forwardRef<HTMLDivElement, DropZoneProps>(
function DropZoneEditInternal(
{
Expand Down Expand Up @@ -252,7 +254,7 @@ const DropZoneEdit = forwardRef<HTMLDivElement, DropZoneProps>(
const componentId = item.props.id;

const puckProps: PuckContext = {
renderDropZone: (props) => <DropZoneEdit {...props} />,
renderDropZone: DropZoneEditPure,
isEditing: true,
dragRef: null,
};
Expand Down Expand Up @@ -344,6 +346,10 @@ const DropZoneEdit = forwardRef<HTMLDivElement, DropZoneProps>(
}
);

const DropZoneRenderPure = (props: DropZoneProps) => (
<DropZoneRender {...props} />
);

const DropZoneRender = forwardRef<HTMLDivElement, DropZoneProps>(
function DropZoneRenderInternal({ className, style, zone }, ref) {
const ctx = useContext(dropZoneContext);
Expand Down Expand Up @@ -395,9 +401,7 @@ const DropZoneRender = forwardRef<HTMLDivElement, DropZoneProps>(
<Component.render
{...item.props}
puck={{
renderDropZone: (props: DropZoneProps) => (
<DropZoneRender {...props} />
),
renderDropZone: DropZoneRenderPure,
}}
/>
</DropZoneProvider>
Expand Down

0 comments on commit 63b8b9a

Please sign in to comment.