question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Docs question] useForm

See original GitHub issue

Are you submitting a bug report or a feature request?

Question about the documentation

What is the current behavior?

The doc states:

The useForm hook plucks the FormApi out of the React context for you. It will throw an exception if you try to use it outside of a <Form> component.

Which confused me at first, because what would be the use of useForm if you still needed Form?

Then I found this Codesandbox: https://codesandbox.io/s/zqkj5706y3, which doesn’t use Form.

I think the doc should be updated, and I would gladly do it but maybe I’m mistaken, or maybe there was some intent behind the original description?

Thanks in advance for looking into it!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
checkmatezcommented, Nov 25, 2019

As I see it, with React hooks we don’t need to render components, unless we want something on the screen. Hooks allows us to reuse stateful logic between “presentational” components. Since Final Form does not have an opinion on visual side of things, it should be possible to use library simply as a collection of hooks.

I think that useForm hook was introduced as a way to consume api of the closest form - analogous children as a function inside <Form>. I propose a new hook useFinalForm - that would have api similar to the <Form> itself.

So usage would look something like:

const MyForm = () => {
  const { ContextProvider, formInstance, handleSubmit, /* rest of FormRenderProps */} = useFinalForm({ onSubmit: () => {...}, /* rest of FormProps */ })
  return <ContextProvider value={formInstance}><form onSubmit={handleSubmit}>{ /* ... */ }</form></ContextProvider>
}

What do you think, @erikras ?

1reaction
adrienharnaycommented, Aug 9, 2019

Ah, I’ve just figured you are using react-final-form-hooks in the sandbox: https://github.com/final-form/react-final-form-hooks#whats-the-difference-between-react-final-form-hooks-and-the-hooks-introduced-in-react-final-form-v5, though I did not completely understand why RFF’s useForm couldn’t be like RFF-hooks’.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useForm | React Hook Form - Simple React forms validation
useForm is a custom hook for managing forms with ease. It takes one object as optional argument. The following example demonstrates all of...
Read more >
Choose a question for your form - Google Docs Editors Help
You can include up to 2000 total choices and collect several types of answers in your form or quiz. Learn how to add...
Read more >
Tech Tip # 86 - Create a google form that automatically fills ...
This video demonstrates how you can create a google form that pulls question choices from a spreadsheet and eliminates them as form choices ......
Read more >
How to build Google Forms from the contents of Google Docs?
Form Builder for Docs ” helps you to build Google Forms in a very simple and ... loading contents from existing Google Docs...
Read more >
Form Builder - Video 3 - Import From Google Docs - YouTube
Import fields, questions and answers from Google Document straight into Google Forms using Form Builder. You can import any Google Doc of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found