Great article thank you. I'm not sure, would this be a good way to go about a state change? I’m using Context for this.
Basically, it serializes the prevState and App.js state into JSON and compares them. I’m not sure if I have a function I don’t need, I think I do need: setUser
so the child/grandchild/etc can update.
If you get a moment any thoughts are appreciated.
App.js
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
user: {
id: null,
isAuthed: false,
firstName: false
},
setUser: this.setState({ user })
}; componentDidUpdate = (prevProps, prevState) => {
if (prevState.user.toString() == this.state.user.toString()) {
return false;
} this.setState((prevState) =>
(prevState, {user})
);
} render() => {
// ...
return ( <div>fake</div> )
}
}