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

context-based comps, hooks and missing provider in 2.0 #1477

Closed
slorber opened this issue Apr 30, 2019 · 2 comments
Closed

context-based comps, hooks and missing provider in 2.0 #1477

slorber opened this issue Apr 30, 2019 · 2 comments
Labels

Comments

@slorber
Copy link
Collaborator

slorber commented Apr 30, 2019

Hi,

Currently, it's possible to use formik in v2 which does not require a parent FormikProvider

But this will make all components using FormikContex to fail. It's actually a bit nasty because there's no warning on mount, but as the context methods are not injected into the consumer components, we get this kind of errors:

image

I think we should

1) Make it fail fast

const form = useFormik()
return <FieldArray>...</FieldArray>

This should crash/error on mount instead of on attempt to modify form

2) Document that this is possible:

const form = useFormik()
return <FormikProvider value={form}><FieldArray>...</FieldArray></FormikProvider>

It's a workaround I'll use temporarily (as I'm for strong typesafety/manual typesafe wiring, I try to avoid using context-based components)

3) Allow all context-based components to be able to receive the form as props

const form = useFormik()
return <FieldArray form={form}>...</FieldArray>
@slorber slorber changed the title context-based components and hooks in 2.0 context-based comps, hooks and missing provider in 2.0 Apr 30, 2019
@jaredpalmer
Copy link
Owner

All context based components and hooks should crash with a warning. In a perfect world there is a formik.getFieldArrayHelpers that can be used without context just like formik.getFieldProps

@stale stale bot added the stale label Jun 30, 2019
@maddhruv
Copy link
Collaborator

Closing due to long inactivity

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

No branches or pull requests

3 participants