final-form / final-form/react-final-form
[Feature request] useFormApi
- Dominant language
- JavaScript
- Stars
- 7.4k
- Forks
- 497
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
`useForm` allows you to use the `FormApi` of the current context, it does not work outside of a ``, it's normal.
It would be practical to be able to create a `FormApi` before the render of ``, which would make it possible to reuse it in other hooks.
For that I copied your `useConstant` then:
```jsx
function MyComponent() {
const form = useConstant(() => createForm({
initialValues,
onSubmit
}));
const myCallback = useCallback(() => {
form.reset(); // for example
}, []);
return (
);
}
```
It could be simplified with something like this:
```js
const useFormApi = config => useConstant(() => createForm(config));
```
Contributor guide
Assessment
This issue has not been assessed yet.