React Portal as sibling of html element

32 Views Asked by At

i would like to know if there is a way to use createPortal to render a component in React, but istead of appending as last child of a container, to render it next to a specific container, like next to a specific element of a list and so on

<div id='parent-container'>
  
   <div id='next-to-me'>
   </div>

   <div>
   // other stuff
   </div>
</div>

const PortalComponent = ()=>{

return createPortal(<div></div>, document.getElementById('parent-container'))
}

// This will put PortalComponent as last child of the container but how to render it as second child for example?

0

There are 0 best solutions below