react-three-flex
react-three-flex copied to clipboard
Correct node ordering on mount/unmount
If something unmounts-mounts it will be placed to the end of the flex, ignoring ordering: https://github.com/react-spring/react-three-flex/blob/master/src/Box.tsx#L186
// Make child known to the parents yoga instance *before* it calculates layout
useLayoutEffect(() => {
if (!group.current) return () => {}
parent.insertChild(node, parent.getChildCount())
registerBox(group.current, node, flexProps, centerAnchor)
// Remove child on unmount
return () => {
parent.removeChild(node)
if (group.current) {
unregisterBox(group.current, node)
}
}
}, [node, parent, flexProps, centerAnchor])