DEV Community 👩‍💻👨‍💻

Simler Li
Simler Li

Posted on

How to move react component and it's html element into another parent component?

I'm working on building a low code WYDIWYG platform to build web pages. So we need to drag a component(also a react component) from an old parent to a new one. The component should be reused to prevent destroy and rebuild it. The dom elements(vnode tree) of the component should be kept cause of some third party libs may alter dom directly.

In other words, move a react component to another parent component whit it's html element.

These components don't need props and other interactions with it's parent.

Top comments (1)

brense profile image
Rense Bakker

There's no react way to do that. You'd need to get a Html element ref for your container and your child component and then move it with append.

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.