Understanding React v16.4+ New Component Lifecycle Methods
Mahesh Haldar
1.3K3

Thanks a lot for the summary. It explains it well. However I wonder how would you refactor code like this to the React 16.4+.

class Example extends React.Component {
constructor(props) {
super(props);
this.pluginWrapperElRef = React.createRef();
}
componentDidMount() {
this.pluginInstance = new ExtraPlugin({
el: this.pluginWrapperElRef,
config: this.props.extraPluginConfig,
});
}
// PART TO REFACTOR
componentWillReciveProps(newProps) {
if (newProps.extraPluginConfig !== this.props.extraPluginConfig) {
this.pluginInstance.updateConfig(newProps.extraPluginConfig);
}
}
// end of PART TO REFACTOR
render() {
<form>
<input type="text" />
<div ref={this.pluginWrapperElRef} />
</form>
}
}

Thanks!