React native flushSync alternative

Viewed 37

I am refactoring my code after updating from react native 0.67 to 0.69.5, thus adding react 18 to the app. I have some code like the following, where doSomething() uses userInfo internally. The point is to make sure I'm only calling doSomething() when I have to most recent version of userInfo.

useEffect(() => {
   doSomething()
}, [userInfo])

const handleLoginButton = async () => {
   const info = await fetchUserInfo();
   setUserInfo(info);
}

Which I acknowledge that is a bad use of useEffect from recent discussions. So I wish to refactor to something like

const handleLoginButton = async () => {
    const info = await fetchUserInfo();
    flushSync(() => {setUserInfo(info))};
    doSomething();
}

But flushSync is imported from react-dom. I do know that I could just doSomething(info), but that would need a lot more of refactoring in the actual code. Is there any way of achieving this using react-native instead of react-dom?

0 Answers
Related