New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap side effects to fix new warnings in React 16.13 #317
Conversation
revalidate: swr.revalidate, | ||
isValidating: swr.isValidating, | ||
mutate: swr.mutate | ||
// hoist side effects: setPageSWRs and setPageOffsets -- https://reactjs.org/blog/2020/02/26/react-v16.13.0.html#warnings-for-some-updates-during-render |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// hoist side effects: setPageSWRs and setPageOffsets -- https://reactjs.org/blog/2020/02/26/react-v16.13.0.html#warnings-for-some-updates-during-render |
Okay to delete this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to keep it! :)
isValidating: swr.isValidating, | ||
mutate: swr.mutate | ||
// hoist side effects: setPageSWRs and setPageOffsets -- https://reactjs.org/blog/2020/02/26/react-v16.13.0.html#warnings-for-some-updates-during-render | ||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to hoist is useEffect()
s, possibly with dependency arrays to take the place of the if
clauses below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
Fix for #290 "Warning in React 16.13.0"
New warnings in React 16.13 — especially triggering
setState()
from another component.This change:
setTimeout()
around twosetState()
calls inuseSWRPages()
. There's a comment in it that we can probably delete.setState()
. But that's actually the point of the new warnings, I think.