Skip to content

Main tutorial is confusing and some parts are broken (getFieldProps) #2511

@jdahdah

Description

@jdahdah

📖 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:

  1. Input fields lose their type, and thus their styling. I've added those in but it doesn't solve the next issue.
  2. Validation is broken. Apart from showing that a field is required, features like checking for the correct character count or the pattern of an email address are no longer working. It just says "Required".
  3. If you 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)
  4. The tutorial uses 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:
validation before

After:
CleanShot 2020-06-06 at 17 52 51@2x

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 understand getFieldProps 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions