final-form / final-form/react-final-form

[Feature request] useFormApi

Open
#782 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.