Skip to content

Commit

Permalink
chore: lazyloading DragDropContext
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed May 24, 2022
1 parent ce2171e commit 46ea52d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/withDNDContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { DragDropContext } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';
import React from 'react';
import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';

export default DragDropContext(HTML5Backend);
const withDNDContext = (component) => {
const DNDConnector = (props) => {
const { DragDropContext } = props.reactDnd;
const HTML5Backend = props.reactDndHtml5Backend.default;

const DNDSubblocks = React.useMemo(
() => DragDropContext(HTML5Backend)(component),
[DragDropContext, HTML5Backend],
);

return <DNDSubblocks {...props} />;
};
return injectLazyLibs(['reactDnd', 'reactDndHtml5Backend'])(DNDConnector);
};

export default withDNDContext;

0 comments on commit 46ea52d

Please sign in to comment.