Perhaps I got a wrong understanding of react flow, but can someone explain this magic :)
Why I have to update inner state through the useEffect hook in React?
I thought the component updating will trigger rewriting the initial state of useState hook.
const [list, setList] = useState<TabItem[]>(tabs);
useEffect(() => {
setList(tabs);
}, [tabs]);
useEffect
in this example will run after state has been instantiated and the component rendered out, and you don't need auseEffect
hook to update state, you can invoke the state updater anywhere. Your question isn't very clear. Perhaps you could include a more comprehensive code example? – Drew Reese