Bug: `useActionState`'s second argument is not optional in the React types
React version: 19.2
Steps To Reproduce
useActionState(action)currently throws a type error.
The current behavior
I'm building a library that makes use of React Actions for mutations. There is no need to pass an initial state variable for useActionState. An "implicit undefined" initial state is perfectly fine and saves people from typing 6 characters each time.
When I omit the second argument, React appears to be working just fine. However, @types/react expects the second argument to be provided. Can we make it optional or is there a reason to keep it required?
The expected behavior
useActionState(action) should not throw a type error.
I submitted a PR for @types/react here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/74156
cc @eps1lon @rickhanlonii @sophiebits (who appear to have had major input on useActionState's design based on past PRs)
We don't allow implicit undefined in useState, useContext etc either. The docs also mark the initial state as required: https://react.dev/reference/react/useActionState
My specific use case is that I'm using a framework that provides actions for useActionState, like:
const […] = useActionState(frameworkProvidedAction, null);
The framework handles all the action code and does not need access to the previous state. However, as a user I have to pass the initial value unnecessarily every time. I assume in 90%+ of cases the user does not need to set the initial result of the action to anything but null/undefined.
Another solution is to provide a hook that wraps useActionState, but that's more API surface for very little benefit.