setRecoilState requires re-rendering #1982
Unanswered
Leykwan132
asked this question in
Q&A
Replies: 1 comment
-
Setting Recoil state may cause subscribing components to re-render, but there are optimizations which avoid it in some cases such as when changing the state to the same value. In general, don't rely on the number of renders for semantic reasons. It's not clear why re-rendering would crash your application without an example. For syncing atoms with localStorage, consider atom effects |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
const profileData = useRecoilValue(profileState);
const setProfileUrl = useSetRecoilState(profileState);
useEffect(() => {
setProfileUrl(JSON.parse(window.localStorage.getItem("profileData")));
console.log(profileData)
}, []);
I am trying to set the atom to the localStorage value when the user refreshes the page, but it seems like setRecoilState requires a re-render which would potentially crash the application. Any solution to this, thanks!
Beta Was this translation helpful? Give feedback.
All reactions