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

formik 1.5.8 useFormik and useFormikContext not a function #3917

Open
inspiraller opened this issue Nov 20, 2023 · 1 comment
Open

formik 1.5.8 useFormik and useFormikContext not a function #3917

inspiraller opened this issue Nov 20, 2023 · 1 comment

Comments

@inspiraller
Copy link

Bug report

Current Behavior

There does not seem to be a method useFormik or useFormikContext, despite 'FormikProvider' not breaking anything.

Expected behavior

  • useFormik should be a function
  • useFormikContext should be a function

Reproducible example

FormItem.jsx

const FormItem = (props) => {
    const formikProps = useFormikContext(); // useFormikContext is not a function (but its wrapped in Provider - see below)
}

FormWrapper.jsx

import React from "react";
import { Form, useFormik, Formik, FormikProvider } from "formik";
import PropTypes from "prop-types";
import FormItem from "./FormItem";
const MyForm = () => {
  // Can't use useFormik here. It says useFormik is not a function.
  // const formik = useFormik
    return (
        <Formik
            initialValues={{
                first_name: "",
                last_name: "",
                phone_number: "",
            }}
        >
            <Form>
                <FormikProvider> {/* this does not cause an error, so I would asume useFomik should work on next page */}
                    <FormItem />
                </FormikProvider>
            </Form>
        </Formik>
    );
};
export default MyForm;

Suggested solution(s)

?

Additional context

?

Your environment

Software Version(s)
Formik 1.5.8
React 17
TypeScript NO
Browser chrome
npm/Yarn yarn 1.22
Operating System ubuntu
@sergei-maertens
Copy link

I don't think formik v1 supports hooks, see the upgrade instructions: https://formik.org/docs/migrating-v2

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

No branches or pull requests

2 participants