Formik: arrayHelpers at FieldArray doesnt work at formik 2.0 w/ hooks

Created on 2 May 2019  路  2Comments  路  Source: formium/formik

馃悰 Bug report

Current Behavior

When try to insert, remove or push
If tryied on codesandbox, nothing happens.

if tried on vscode, throws an error, check the print:
Screenshot_20190501_194340

Expected behavior

To handle correctly the array helpers.

Reproducible example

https://codesandbox.io/s/kxlowwpn8r

Additional context

Formik 2.0 with hooks

Your environment

| Software | Version(s) |
| ---------------- | ---------- |
| Formik | 2.0 and ^2.0.1-alpha.2
| React | 16.8.6
| TypeScript |3.4.5
| Browser | Google chrome 74
| npm/Yarn | 1.15.2
| Operating System | Manjaro

Most helpful comment

The codepen isn't working but i think that the problem is because its not provided a context of formik to FieldArray to access the helpers from formik.

import { useFormik, FormikProvider } from 'formik'

const TestForm = () => {
  const formikbag = useFormik({
    initialValues: { name: '' },
    onSubmit: values => console.log(values),
  })

  return (
    <FormikProvider value=(formikbag)>
      {/* Fields and FieldArrays */}
    </FormikProvider>
  )
}

export default TestForm

OBS: The component uses the useFormik hook and the FormikProvider to provide the helpers to components like FieldArray (abstract the logic to simplify the usage).

All 2 comments

The issue is still present in the latest RC.

The codepen isn't working but i think that the problem is because its not provided a context of formik to FieldArray to access the helpers from formik.

import { useFormik, FormikProvider } from 'formik'

const TestForm = () => {
  const formikbag = useFormik({
    initialValues: { name: '' },
    onSubmit: values => console.log(values),
  })

  return (
    <FormikProvider value=(formikbag)>
      {/* Fields and FieldArrays */}
    </FormikProvider>
  )
}

export default TestForm

OBS: The component uses the useFormik hook and the FormikProvider to provide the helpers to components like FieldArray (abstract the logic to simplify the usage).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dearcodes picture dearcodes  路  3Comments

ancashoria picture ancashoria  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments

emartini picture emartini  路  3Comments

jordantrainor picture jordantrainor  路  3Comments