Skip to content
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

Add missing validationSchema to Formik context #2933

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JoseLion
Copy link

@JoseLion JoseLion commented Nov 28, 2020

Hi @jaredpalmer, @johnrom!

I noticed the validationSchema was missing when using useFormikContext. The types say it's there, but it always returns undefined. I took a look, and it seems it was missing from the context value definition, so I decided to open this small PR to lend a hand with this.

Hope this helps 🙂

@changeset-bot
Copy link

changeset-bot bot commented Nov 28, 2020

⚠️ No Changeset found

Latest commit: eb55e7a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Nov 28, 2020

@JoseLion is attempting to deploy a commit to the Formium Team on Vercel.

A member of the Team first needs to authorize it.

@johnrom
Copy link
Collaborator

johnrom commented Nov 30, 2020

This is ok by me especially since it exists in the types already. The only issue I see with it is that some users may create a new Yup object on each render. and if that's the case, this prop will change on every render, and cause more updates. Not sure how much of a problem that is. I don't use Yup, so I'll defer to someone else whether that's an issue or not.

@johnrom
Copy link
Collaborator

johnrom commented Nov 30, 2020

related #2751

@JoseLion
Copy link
Author

JoseLion commented Dec 1, 2020

@johnrom thank you for your response 🙂 I think the most common use-case will be exactly what is mentioned in #2751. As I think about it, it seems unlikely that a new Yup object is created on each render, but it could happen. I hope it's not much of a problem because that is the only way of getting validation info into abstracted field components. 😅

@JoseLion JoseLion force-pushed the fix-validation-schema-missing branch from 93a41f0 to 24716ac Compare December 5, 2020 02:49
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2021

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label Jan 5, 2021
@johnrom johnrom removed the stale label Jan 5, 2021
@JoseLion JoseLion force-pushed the fix-validation-schema-missing branch from 24716ac to 7d793e2 Compare January 9, 2021 17:58
@JoseLion
Copy link
Author

JoseLion commented Jan 9, 2021

@jaredpalmer any news on this one? It's not super critical, but I think it would be great to have this 🙂

Cheers!!

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2021

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label Feb 9, 2021
@noisyscanner
Copy link

Any movement on this? Would be very useful to us

@johnrom johnrom removed the stale label Feb 19, 2021
@JoseLion JoseLion force-pushed the fix-validation-schema-missing branch from 7d793e2 to 6797460 Compare February 19, 2021 16:55
@JoseLion
Copy link
Author

I just updated the branch, so this is ready to merge if there're no concerns 🙂

@github-actions
Copy link
Contributor

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label Mar 22, 2021
@johnrom johnrom removed the stale label Mar 22, 2021
@johnrom
Copy link
Collaborator

johnrom commented Mar 22, 2021

I don't think we should pass through this or the validate callback through the default Formik React context because of the high chance it has not been optimized. If it isn't optimized, it will trigger re-renders in every single component which uses Context to access Formik, and configuration is much less likely to be needed by users than Formik's API or state.

I'd be open to passing these values via a secondary Context which contains only Formik Configuration:

const Formik = () => {
  // formikApi is completely memoized
  // formikConfig is more volatile based on usage
  const [formik, config] = useFormik(...formikProps);

  return <FormikProvider value={formik}>
    <FormikConfigProvider value={config}>
      {/* children */}
    </FormikConfigProvider>
  </FormikProvider>
}

const useFormikConfig = () => useContext(FormikConfig.Consumer);

@jaredpalmer if this is something we want to do, I can make these changes to my v3 branch

@johnrom johnrom mentioned this pull request Mar 23, 2021
1 task
@JoseLion JoseLion force-pushed the fix-validation-schema-missing branch from 6797460 to f1545e8 Compare April 5, 2021 03:50
@JoseLion
Copy link
Author

JoseLion commented Apr 5, 2021

I updated this branch just in case. Thanks again @johnrom for looking into this 🙂

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2021

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label May 6, 2021
@noisyscanner
Copy link

@github-actions plz no

@johnrom johnrom removed the stale label May 6, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2021

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label Jun 6, 2021
@johnrom johnrom removed the stale label Jun 6, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2021

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label Jul 7, 2021
@johnrom johnrom removed the stale label Jul 7, 2021
@johnrom
Copy link
Collaborator

johnrom commented Jul 7, 2021

FYI this change is available in my v3 PR #3231

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2021

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

@github-actions github-actions bot added the stale label Aug 7, 2021
@JoseLion JoseLion force-pushed the fix-validation-schema-missing branch from f1545e8 to eb55e7a Compare August 15, 2021 18:53
@JoseLion
Copy link
Author

@johnrom I updated this branch just in case. However, it's great to know this is coming in v3, is there an ETA for v3 yet? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants