CodeZeus
1 min readJan 15, 2019

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> )
}
}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

CodeZeus
CodeZeus

Written by CodeZeus

Software Developer Jesse Boyer, known more by JREAM. Hobbyist and Professional Developer.

No responses yet

Write a response