Replies: 1 comment 1 reply
-
I've never seen this "hasn't mounted yet" version of this error. My initial thought is it doesn't make sense since you can set state during initial render in React - before the component mounts - just fine: function Repro() {
const [state, setState] = useState('a')
if (state === 'a') setState('b') // works
} So this needs some digging. Some DiggingIt looks like this is a simple race condition with suspense. Turns out it's very easy to repro: let counter = 0
function Repro() {
const [state, setState] = useState('a')
if (counter++ === 0) {
throw Promise.resolve().then(() => setState('b'))
}
return <div>Repro state: {state}</div>
} Since the component is essentially "unmounted" immediately when it suspends, any Alternative repro: let counter = 0
function Repro() {
const [state, setState] = useState('a')
if (counter++ === 0) {
setTimeout(() => setState('b'), 5)
throw new Promise(resolve => setTimeout(() => resolve(null), 10))
}
return <div>Repro state: {state}</div>
} I also found this TanStack Table issue: TanStack/table#5026. Though they all seem to be saying it's a StrictMode-only thing. I can't repro with StrictMode alone without suspense. Some Plot ThickeningSo now you'd think reproing this with Zedux hooks would be easy. But there are two problems:
Zedux hooks waits until their I don't think any behavior around this error would be different with React Native. StrictMode doesn't seem to change anything either. So I'm stuck here. I can spend some more time on it tomorrow. What version of React and Zedux are you using @joprice? |
Beta Was this translation helpful? Give feedback.
-
I'm using zedux in a react native app and have been seeing the error for a few months.
Can't perform a React state update on a component that hasn't mounted yet
. It happens when I use suspense as a parent of an async data-only atom. I've dug for a while on multiple occasions to see if it's something I'm doing wrong, but can't find any unmanaged effects or other misuse. Could there be any way that the suspense handling of zedux is triggering a state update during rendering, as the warning states?Beta Was this translation helpful? Give feedback.
All reactions