mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
eeb35792f23e561e835c390dc9f8e329342d9250
This implements useFormState in Fiber. (It does not include any
progressive enhancement features; those will be added later.)
useFormState is a hook for tracking state produced by async actions. It
has a signature similar to useReducer, but instead of a reducer, it
accepts an async action function.
```js
async function action(prevState, payload) {
// ..
}
const [state, dispatch] = useFormState(action, initialState)
```
Calling dispatch runs the async action and updates the state to the
returned value.
Async actions run before React's render cycle, so unlike reducers, they
can contain arbitrary side effects.
DiffTrain build for [456d153bb5](https://github.com/facebook/react/commit/456d153bb582798effa76c09bec2405ab2e392cf)
Please do not delete this branch
Languages
JavaScript
67.1%
TypeScript
29.4%
HTML
1.5%
CSS
1.1%
C++
0.6%
Other
0.2%