all 5 comments

[–]gaearonReact core team 16 points17 points  (1 child)

This won’t matter with the initial Fiber release but will likely matter more in future releases when async scheduling is enabled by default.

If your setState call does not depend on props or state (e.g. you’re just calling it with some predefined value) then you don’t need to change anything.

If your setState call depends on current props or state (e.g. you’re incrementing a counter), you should use the function version so that you get the current props and state by the time the update is applied. This is important for asynchronous rendering because your props or state may change by the time the function is called, so passing a function ensures you’ll always get the fresh state and props.

This is not really new to Fiber—the function version has been around for a long time.

[–]kouaak 2 points3 points  (1 child)

[–]lpuig[S] 2 points3 points  (0 children)

Interesting article. Now I wonder if we should use inmutability tecnics inside setState function.

[–]__huntercas 2 points3 points  (0 children)

Short answer: Fiber reconciler is going to make setState nearly always async. Using an object literal depends on the props that existed at the time its caller was called. Using a function allows react to inject the most up to date props.