Want to avoid memory leaks from jQuery? componentWillUnmount is called right before your component is unmounted from the DOM, it’s the right place to clean up all external references / event listeners / dom elements your component might have created during its lifetime.
1 2 3 4 5 6 7 8 9 10 11 | var MyComponent = React.createClass({ componentDidMount() { $(React.findDOMNode(this.refs.jqueryPluginContainer)).plugin(); }, componentWillUnmount() { $(React.findDOMNode(this.refs.jqueryPluginContainer)).plugin('destroy'); }, render() { return <div ref="jqueryPluginContainer" />; }, }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.