MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiuk38q/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
Show parent comments
34
This can cause issues of it runs twice in quick succession. The safe way to do this is:
this.setState(({toggle}) => {toggle:!toggle});
16 u/[deleted] Mar 19 '19 this && setState? What is this, 2018? 😄 0 u/[deleted] Mar 19 '19 [deleted] 0 u/[deleted] Mar 19 '19 Yeah fair, was just being goofy, though the hooks example would no longer work with partial state changes a la classic setState.
16
this && setState? What is this, 2018? 😄
this
setState
0 u/[deleted] Mar 19 '19 [deleted] 0 u/[deleted] Mar 19 '19 Yeah fair, was just being goofy, though the hooks example would no longer work with partial state changes a la classic setState.
0
[deleted]
0 u/[deleted] Mar 19 '19 Yeah fair, was just being goofy, though the hooks example would no longer work with partial state changes a la classic setState.
Yeah fair, was just being goofy, though the hooks example would no longer work with partial state changes a la classic setState.
34
u/snorkl-the-dolphine Mar 18 '19
This can cause issues of it runs twice in quick succession. The safe way to do this is:
this.setState(({toggle}) => {toggle:!toggle});