I am trying to refactor the following into ES6 as a functional component. I considered looking into lodash decorators: https://www.npmjs.com/package/lodash-decorators#bind but are there tips on approaching refactoring class components like this to functional components compliant with ES6, especially when the logic in the lifecycle component methods get more complex?
constructor(props) {
super(props);
this._isMounted = false;
this.state = {
profilePictureFailedToLoad: false,
};
if (process.browser) {
this.profileImage = new Image();
this.profileImage.src = this.props.userInfo.userAssetUrl;
}
this.handleLoginClick = this.handleLoginClick.bind(this);
this.handleLogoutClick = this.handleLogoutClick.bind(this);
this.handleProfileClick = this.handleProfileClick.bind(this);
this.handleModalClose = this.handleModalClose.bind(this);
this.handleDeleteAccountClick = this.handleDeleteAccountClick.bind(this);
this.handleDeleteAccountModalClose = this.handleDeleteAccountModalClose.bind(this);
}
componentDidMount() {
this._isMounted = true;
}
componentDidUpdate(prevProps) {
if (this.props.router.query.login === "true" && prevProps.router.query.login !== "true") {
console.log("Updating...")
}
}
componentWillUnmount() {
this._isMounted = false;
}