2 ms·
> it actually schedules a state update to be performed later when React feels like it. I thought it updates the state and the re-render is what is included in
by purple_ducks 8y ago
> it actually schedules a state update to be performed later when React feels like it.
I thought it updates the state and the re-render is what is included in a scheduled function?
> it's best practice to provide an updated function rather than a plain object
I'm guessing you mean for a global store with shared state? Local components aren't singletons.
- Vinnl 8y ago> I thought it updates the state and the re-render is what is included in a scheduled function? See here: https://reactjs.org/docs/react-component.html#setstate https://reactjs.org/docs/react-component.html#setstate > setState() enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the updated state. (Emphasis mine.) > I'm guessing you mean for a global store with shared state? Local components aren't singletons. No, local state, the one you set using `setState`. The offical docs don't actually recommend always using an updater function, but it's the primary method they explain, and my inclination is to better be safe than sorry: > If the next state depends on the current state, we recommend using the updater function form, instead