3 ms·
Definitely, it crossed my mind, I just have not had enough time to write an minimal bug example unfortunately :/ In this case I think the problem is `setState`
by kaoD 8y ago
Definitely, it crossed my mind, I just have not had enough time to write an minimal bug example unfortunately :/
In this case I think the problem is `setState` is inside my `useEffect` and I'm using its dependencies array as a sort of substitute to `componentWillUpdate` + compare `props` to `prevProps` (hence the async state update).
In class-based react I would just atomically `setState` both states and there would be no problem, but since hooks allow you to modularize behavior a new type of data dependency appears (there are multiple states in a single component) making it harder to reason.
Thanks for chiming in, will file an issue ASAP.
- danabramov 8y agoNo problem, I'm sorry for the confusion. I think your use case might be solved by this approach: https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-g...