Skip to content

useFormContext for multiple (n) forms in the page #208

Answered by airjp73
ayrtonvwf asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

If all you're doing is resetting after submit, you can use the reserAfterSubmit prop. If you're resetting on a button press, you can use the native <button type="reset" /> instead of the hook.

More generally about the useFormContext hook, you have a couple options depending on your case.

  1. If you use useFormContext from a descendant of the ValidatedForm, maybe by pulling your logic into a component, you can omit the form id entirely.

  2. You can use a dynamic value for the form id. If you have a list of posts, I'm guessing the post has some sort of id you can use.

const PostForm = ({ postId }) => {
  const formId = `post-${postId}`;
  const context = useFormContext(formId);

  // Pass…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ayrtonvwf
Comment options

Answer selected by ayrtonvwf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants