Patch Changes
-
#486
64d0c6eThanks @hyesungoh! -buildContextnow setsdisplayNameon the returnedProviderto`${contextName}Provider`, so React DevTools shows which context a provider belongs to instead of a bareProvider. The documentation example also passednullas the default values, which the signature rejects; it now passes an object. -
#484
c974fdcThanks @hyesungoh! -useControlledStatenow applies multiplesetValuecalls in the same tick in order when uncontrolled, instead of computing each from the value captured at render. This affects both function updates and plain values:setValue(prev => prev + 3)twice now adds 6 instead of 3, andsetValue('b')followed bysetValue('a')from a current value of'a'now settles on'a'instead of'b'.As a consequence, in uncontrolled mode
onChangeis called once after the state commits with the final value, rather than synchronously on everysetValuecall. A parent that mirrorsonChangeinto its own state therefore renders once more per update, no call is made when the final value equals the previous one, and a change reported by a component that unmounts in the same commit is dropped. Under StrictMode a single change is now reported once instead of twice.Controlled mode is unchanged: it still computes from the current
valueprop, so two function updates in the same tick see the same previous value. -
#486
64d0c6eThanks @hyesungoh! -mergeRefsnow forwards the cleanup functions that callback refs can return since React 19. When at least one of the merged refs returns a cleanup, the merged ref returns one as well, so React runs those cleanups on detach instead of calling the callbacks withnull; refs that returned nothing are still reset tonullinside that cleanup. When no ref returns a cleanup the merged ref returns nothing, as before, so React 18 keeps its existingnullcall and does not warn.