paol-imi / react-reparenting

The reparenting tools for React
https://paol-imi.github.io/react-reparenting
MIT License
481 stars 8 forks source link

Usage for a slot like approach #21

Open jgoux opened 3 years ago

jgoux commented 3 years ago

Hello,

I was wondering if this library would be usable to directly render a component to another place in the render tree, à la https://github.com/javivelasco/react-tunnels#react-tunnels ? So in my case I would like to send the component to the other place without mounting it locally I guess?

My use case is being able to declare "slots" in my Layout that I can fill from children deep in the tree to have like contextual menus depending on the current page without unmouting/remounting the Layout, so I can have animated page transitions as a bonus!

gurkerl83 commented 3 years ago

@jgoux Hello, a use case of this kind works, I am also experimenting with the library specifically the implementation of a Navigation Component that uses Framer Motion for animation.

Since initial experiments were easy to implement I am at a point where removing a child and reinserting it elsewhere provides a problem. Specifically, the children are subcomponents that represent a list. If a view or a list included in the view is navigated down in the first parent component by the user and in the next step, the view is passed to another parent component, the list snaps back to the first element of the list; the already executed path in the first parent component is thus lost.

Currently I am looking for a way to solve this, hopefully I can get it round.