Do not destroy children which are not created by react
See original GitHub issueDescription
Currently, a code to remove a component from a tree looks like this:
if ((_child$children = child.children) !== null && _child$children !== void 0 && _child$children.length) {
_toConsumableArray(child.children).forEach(function (c) {
_removeChild(child, c);
});
}
parent.removeChild(child);
child.destroy();
It makes an issue with pixi components, which manages children on its own. See issue: https://github.com/pixijs/spine/issues/389
Pixi spine makes children on its own and destroy them in destroy method. Because of it, there is no way to manage component like this in react-pixi, because react-pixi will call destroy for each child and call destroy on the spine component.
I think, there should be a way to manage situation like this.
Steps to reproduce
- Make component like this:
export const SpineComponent = PixiComponent<{ data: ISkeletonData }, OrigSpine>('Spine', {
create: (props) => {
const s = new Spine(props.data);
s.state.setAnimation(0, 'idle_1', true);
return s;
},
didMount: (instance, parent) => {
},
willUnmount: (instance, parent) => {
},
applyProps: (instance, oldProps, newProps) => {
return true;
},
});
- Use the component
- Destroy component from the tree
Additional info
"pixi.js": "6.0.4",
"pixi-spine": "^3.0.3",
"react": "^17.0.2",
"@inlet/react-pixi": "^6.5.2",
"react-dom": "^17.0.2",
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Issues removing specific children in react js - Stack Overflow
When I try to remove a child changing the state it sets an older state... So instead of deleting 1 item it removes...
Read more >Reconciliation - React
When tearing down a tree, old DOM nodes are destroyed. Component instances receive componentWillUnmount() . When building up a new tree, new DOM...
Read more >Portals - React
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. ......
Read more >Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI.
Read more >React.Component
We strongly recommend against creating your own base component classes. ... Note that returning false does not prevent child components from re-rendering ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@inlet It makes sense to group it in object.
Hopefully this fix helps you