-
Notifications
You must be signed in to change notification settings - Fork 142
Formik 2 / <Field as> prop #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… useField and switch from deprecated prop <Field component> to <Field as> syntax.
Interesting. I forgot the new hooks implementation would force a 2.0 upgrade. I will probably only release this once formik 2.0 reaches stable but can do a canary release at some point if we want to test the changes in projects |
Can't be long... Famous last words. Is it not released yet? I see they are
working on 2.0.1-rc12.
Edit: Just saw this in my project: `> formik@2.0.0: This was a mistaken release`
|
package.json
Outdated
{ | ||
"name": "formik-material-ui", | ||
"version": "0.0.20", | ||
"version": "1.0.20", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
versions bumps are automated
package.json
Outdated
"peerDependencies": { | ||
"@material-ui/core": ">=4.0.0", | ||
"formik": ">=1.0.0", | ||
"@material-ui/core": ">=4.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for updating the peer dep here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just so that it was latest. I guess npm/semver will figure that out.
|
||
const fieldError = getIn(errors, name); | ||
const showError = getIn(touched, name) && !!fieldError; | ||
const [field, meta] = useField(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hook should be the in component below
src/TextField.tsx
Outdated
export type TextFieldProps = FieldProps & | ||
Omit<MuiTextFieldProps, 'error' | 'name' | 'onChange' | 'value'>; | ||
FieldConfig & | ||
Omit<MuiTextFieldProps, 'error' | 'onChange' | 'value'>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name should be omitted here
src/TextField.tsx
Outdated
helperText: showError ? fieldError : props.helperText, | ||
disabled: disabled != undefined ? disabled : isSubmitting, | ||
helperText: showError ? error : props.helperText, | ||
disabled: disabled !== undefined ? disabled : false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: !== won't catch null
Is submitting is also needed for users who want to override the behaviour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that simply disabled || false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that works here
mayteio#1 fixed conflict, and specs |
ce76884
to
b49624c
Compare
Addresses #92.
Opening this early for discussion - I've only updated the TextField component. Just want to check I'm on the right track with your vision for the package.
One thing I wasn't sure of was the
name
prop. The new syntax doesn't pass down form, so we don't omit it from theMuiTextFieldProps
type.I'm also unsure on how to access
isSubmitting
- it's only passed to . PotentiallyuseFormikContext()
but then the component will re-render any time the form changes (not ideal).Finally, not sure how you'd want to handle a missing
name
prop or existence ofcomponent
prop - I've thrown a TypeError for now.Any thoughts? Should I push on with the other components?
Cheers!