Git Product home page Git Product logo

Comments (4)

jaredpalmer avatar jaredpalmer commented on May 4, 2024

The initial thinking was that handleChangeValue would mostly be used with custom inputs which don’t always expose legit onBlur. However I now agree that that is asymmetric.

Instead there should be a handleBlurValue and handleChangeValue should accept an optional 3rd argument to blur.

Which brings me to my next point which is that handleChangeValue/handleBlurValue should probably be named differently as they are not really event handlers, they should be like setFieldValue and setFieldTouched

from formik.

eonwhite avatar eonwhite commented on May 4, 2024

Yeah I think you're right. What if we broke out to:

setValue(field, value) - sets the field value but does not set touched state
touchValue(field, value) - sets and touches the field value
touchField(field) - touches the field

from formik.

jaredpalmer avatar jaredpalmer commented on May 4, 2024

@eonwhite

touched doesn't have a singular in english that makes any sense.

What about this API?

// values
handleChange: (e) => void
setFieldValue: (field: string, value: any, touch?: boolean)  => void
setValues: (values: V) => void

// errors
setFieldError: (field: string, msg: string) => void
setErrors: (errorsObject: FormikError) => void

// touched 
handleBlur: (e) => void
setFieldTouched: (field: string, value: boolean)  => void
setTouched: (touchedObject: FormikTouched) => void

// error
setError: (e: any) => void

from formik.

eonwhite avatar eonwhite commented on May 4, 2024

I think the above API looks good and consistent to me.

The one I'm still a little uncertain about is the optional touch? parameter on setFieldValue. It means the component is implementing a callback signature that seems slightly idiosyncratic and specific to Formik, reducing reusability of the component in non-Formik forms.

But it feels appropriate to give the component control over when and whether to perform a touch, rather than leaving that up to the user of the component, so I think it's probably worth the tradeoff.

from formik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.