-
-
Save amanshu-kataria/92fe6bb6962962a0a45abaee4cb4dfa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static getDerivedStateFromProps(nextProps, prevState){ | |
if(nextProps.someValue!==prevState.someValue){ | |
return { someState: nextProps.someValue}; | |
} | |
else return null; | |
} | |
componentDidUpdate(prevProps, prevState) { | |
if(prevProps.someValue!==this.props.someValue){ | |
//Perform some operation here | |
this.setState({someState: someValue}); | |
this.classMethod(); | |
} | |
} |
Hi this is good, but how can i mutate the state
Any way i got it thanks @ProiOSDeveloper
this.setState({someState: someValue});
shouldn't this be:
this.setState({ someState: this.props.someValue });
?
@ragabmoh anything is fine. It's just for purpose of example.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this.setState({someState: someValue});
shouldn't this be:
this.setState({ someState: this.props.someValue });
?