-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Main tutorial is confusing and some parts are broken (getFieldProps) #2511
Comments
Tip on debugging formik forms that I find useful: Print out |
@hrgui Thank you for answering all of my points in detail, I really appreciate it. It sounds like the quickest way to fix this and remove confusion for newcomers is to:
I'll create a PR for task no. 2, but for task no. 1 I assume that @jaredpalmer would prefer to use a CodeSandbox saved under his own username for the official documentation? |
Not a very helpful answer. It states what the problem is very well, but then provides no solutions. |
The tutorial is essentially backwards. It's supposed to be demonstrating "look how easy Formik makes this by putting all this complex logic into these small boilerplate-free components", but it's not clear about it. You shouldn't start with The above performance concerns are going away with #3231, and I will rewrite the documentation to start boilerplate-free and then illustrate when to step out of the basic components.
It's true in v2, but useFormik also has performance issues in that it causes renders on every change to the parent component which require careful memoization at the root level. In v3, I have done away with all of these concerns (except for function-as-children), and now TL:DR; until I have a chance to formalize a release (I'm currently working on a documentation strategy to keep the docs up to date with real code and prevent these issues), I'd recommend using the base components |
📖 Documentation
I'm working through the main tutorial on the Formik website, trying to understand how it works. The flow is good initially and it helps me to understand how Formik makes life easier, up until you reach the section about getFieldProps. It does not seem to be working correctly, and a number of features that the code examples did correctly in previous steps just stopped working. This issue is not meant as a complaint, but to point out the perspective of a first time user. I genuinely don't know how to proceed now, apart from moving on to the next step and hoping that code works.
Problems:
type
, and thus their styling. I've added those in but it doesn't solve the next issue.console.log('getFieldProps('firstName')
, it does not seem to return the object that the migration docs suggests it returns (see After: screenshot below, the error is only due to logging and can probably (?) be ignored)useFormik
even though the docs state that you're not supposed to use it. I understand that the tutorial goes on to recommend using<Formik>
but it feels like mixed messaging to introduce a hook that's only for advanced use right at the beginning of the learning journey. Just a minor issue unrelated to the other problems, but worth mentioning because it can be confusing to beginners.Before:
After:
How to reproduce:
For the before state, replace the code in the Starter CodeSandbox with the example in the previous step, Schema Validation with Yup.
For the after state, paste the code from the next step, getFieldProps.
You can also just try this CodeSandbox which has code identical to the tutorial, plus that one
console.log()
.I'm happy to open a PR to add the missing
type
attribute, but I don't know how to fix the other issues. Perhaps someone could help me to understandgetFieldProps
better? The only other mention of it is in the migration docs which does not really go into how it works, and as mentioned above, appears to return something different than the docs state.The text was updated successfully, but these errors were encountered: