Skip to content Skip to sidebar Skip to footer

Formik Element Type Is Invalid

Formik I am new to formik and start using it every time i start learning i got this issue Uncaught Error: Element type is invalid: expected a string (for built-in components) o

Solution 1:

This is a generic error caused by issues with imports. However, from my tests with react@16, it looks like any version below react-dom@16.4 will show this specific error where the element is imported as an object.

This CodeSandbox demonstrates the error: https://codesandbox.io/s/0vrn83o6ww (Change the react/react-dom versions to test your environment)

If you're using react@16, update react-dom to a version >=16.4 and this should fix the error.

Recent versions formik with incompatible versions of react-dom have made this error come up: https://github.com/jaredpalmer/formik/issues/907

Solution 2:

As @brettinternet said, it's generic, and common. Could be that when using export default formikEnhancer(Login), then you need to import it like a non-default class:

import {Login} from'./Login';

For other folks searching, it's also happens when you entirely forget to define your component's default export.

Solution 3:

I got the same error and the problem was a particular component inside Formik, that at the time was just an empty jsx file. I resolved by fixing the component properly. Formik was just warning "there is something wrong inside the Formik tag, friend".

Post a Comment for "Formik Element Type Is Invalid"