4 ms·
Do you want to file an issue? I’d be happy to answer some of these questions and maybe improve the docs. useLayoutEffect is not the recommended way to do it. Y
by danabramov 8y ago
Do you want to file an issue? I’d be happy to answer some of these questions and maybe improve the docs.
useLayoutEffect is not the recommended way to do it. You’re probably missing a simpler solution like setState during render. But I’d need to see the code to be sure, and GitHub issue would be a better place to do it.
- kaoD 8y agoDefinitely, 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...