jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
34k stars 2.79k forks source link

i am getting error even while using useField inside of Formik - Cannot read properties of undefined (reading 'getFieldProps') #3914

Open muhammaddiyor0104 opened 1 year ago

muhammaddiyor0104 commented 1 year ago

i have my own ui library and my form elements uses useField

import React from 'react';
import { TextField } from '../input/Input';

interface Props {
  readonly name: string
}

export function FormInput({name, ...props}:Props) {
  // const [field] = useField(name)
  console.log("field:", props);
  return (
    <TextField {...props} />
  );
}

but when i install my lib and use my fileds inside of formik i am getting this error Cannot read properties of undefined (reading 'getFieldProps')

what i am doing wrong?

rapitkan commented 7 months ago

Same error here with Formik 2.4.5 and Storybook 8.0.8. Did you got the problem solved, @muhammaddiyor0104 ?

erashu212 commented 6 months ago

@muhammaddiyor0104 @rapitkan Please share codesandbox link with the issue

stardustdev commented 4 months ago

Same issue for me

andrburl2 commented 1 month ago

Had this issue lately. I have ui lib with build by vite. I didn't have formik added to external in rollupOptions and it copy all function of formik in build. But of course it have another context and doesn't work with and etc. So I just added it to external in vite.config.ts. Fixed it for me. Perhaps helps somebody

build: {
      rollupOptions: {
        external: ['react', 'react-dom', 'styled-components', 'formik'],
        output: {
          globals: {
            react: 'React',
            'react-dom': 'ReactDOM',
            'styled-components': 'styled',
            formik: 'formik',
          },
        },
      },
    },