feat: let DragDropContextProvider reuse a DragDropManager #1362
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
tl;dr: this PR gives
DragDropContextProvider
an extra prop,manager
, which will be reused instead of creating a newDragDropManager
.Full explanation:
I'm trying to load react-dnd conditionally in our app.
For mobile devices, for example, it doesn't make sense to have the same dnd interactions, so the chunk with this code doesn't need to be loaded at all.
I could almost do this... however I hit a wall: if react-dnd finishes loading a few seconds after the whole app is ready, the user will notice React remounting the whole app, because I had to reparent it with the
DragDropContext
.To avoid this, each component with dnd interactions will be wrapped in a
DragDropContextProvider
, which unfortunately creates a newDragDropManager
-- not ideal.This PR then lets this component receive a
manager
prop, which will be reused instead of creating a newDragDropManager
when rendered.I can do this once in my app by calling
createDragDropManager
at the app's bootstrap level, and then passing it around with my own React context 🙂Unfortunately I'm not sure how to go about docs here.
dnd-core is undocumented, so I'm guessing any attempts of documenting the change to react-dnd would require documenting details about dnd-core (I'm happy to do it with some ideas).