Open forman opened 1 year ago
@forman probably this is the page you are looking for which shows the similar texts that you have highlighted: useReducer You can check with that.
Yeah, may be worth mention in the caveats of the dispatch function docs @Afrin127329 mentioned here: https://react.dev/reference/react/useReducer#dispatch. Want to submit a PR?
First, I like the new React docs a lot! Unfortunately, I can no longer find the following information about
useReducer
that was once available in the docs:The
useReducer
hook returns an array with two elements: the current state and a dispatch function. The dispatch function is used to update the state by calling it with an action object. The dispatch function returned byuseReducer
has a lifecycle similar to that of the component it is used in. It is created when the component mounts and destroyed when the component unmounts. The dispatch function is guaranteed to be stable across re-renders.Is this no longer the case?
On page Lifecycle of Reactive Effects there is a note box saying "In some cases, React knows that a value never changes..." and mentioning
useState
anduseRef
. It would be ideal if the documentation would explicitly enumerate all the stable return values from hooks, i.e., the ones that share the lifecycle of their component.