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.

[v2] Pass setFieldValue in useField's returned value.

See original GitHub issue

🚀 Feature request

Passing setFieldValue in useField’s meta returned value would be interesting for checkboxes.

An example:

const Checkbox = ({ name }) => {
  const [field, meta] = useField(name)
  return {
    <input 
       type="checkbox"
       checked={field.value}
       name={field.name}
       onChange={() => meta.setFieldValue(field.name, !field.value)}
    />
  }
} 

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Ericnrcommented, Dec 2, 2019

@sumgwork you can use useFormikContext and get setFieldValue from that

2reactions
Ericnrcommented, Aug 12, 2019

Uh I should start reading the change logs. I guess it would still be useful for using with other libraries like react-select, but I guess that might be an edge cases you don’t want to cover.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formik setFieldValue Inside a Function - Stack Overflow
That's where I need to set the field value from. I guess what I could do is pass the setFieldValue function as a...
Read more >
useField() - Formik
2 import { useField, Form, FormikProps, Formik } from 'formik'; ... is a subset of the props that you would pass to <Field>...
Read more >
Managing list of form fields with formik through example
value } </span> </div> ); };. Custom hooks are now part of formik >= v2 , useField hook returns a 3-tuple (an array ......
Read more >
useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and ... fields and remount with updated value update(0, {...
Read more >
Top 5 formik Code Examples - Snyk
it('should return context with passed values', () => { const context ... will set value when before unmount, it's needed to wrap setFieldValue...
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