Closed
Description
componentDidMount()
and componentWillUnmount()
allow for DOM manipulation outside React's reach. DOM manipulations done in componentDidMount()
should be undone in reverse order in componentWillUnmount()
. This is currently not possible in components with mixins (see footnote) due to the order in which the events are fired:
Current order:
- mixin1.componentDidMount()
- mixin2.componentDidMount()
- component.componentDidMount()
- mixin1.componentWillUnmount()
- mixin2.componentWillUnmount()
- component.componentWillUnmount()
Correct order:
- mixin1.componentDidMount()
- mixin2.componentDidMount()
- component.componentDidMount()
- component.componentWillUnmount()
- mixin2.componentWillUnmount()
- mixin1.componentWillUnmount()
JSFiddle: http://jsfiddle.net/rickbeerendonk/3cm3sso5/
Full lifecycle example: https://github.com/rickbeerendonk/react-om-examples/blob/d59eda2b67e07d345a44f9552a2ab231b4127f8a/Extra%2002a.%20ComponentLifecycle%20with%20Mixins/jsx/index.html
Footnote: If all the mixins and the component with those mixins are manipulating the DOM.
Metadata
Metadata
Assignees
Labels
No labels