相关疑难解决方法(0)

TypeError:React.createContext 不是一个函数(Nextjs 13 & Formik with Typescript)

我现在尝试使用 Formik 在 NextJs 13 (Typescript) 上创建一个表单。我创建的表单不起作用,然后我尝试添加示例代码片段,Formik如下所示。我创建的表单和 Formik 的示例都仅TypeError: React.createContext is not a function在控制台中返回。(sc_server)/./node_modules/formik/dist/formik.cjs.development.js我可以在另一行控制台错误中看到这一点。

import * as React from 'react';
import {
  Formik,
  FormikHelpers,
  FormikProps,
  Form,
  Field,
  FieldProps,
} from 'formik';

interface MyFormValues {
  firstName: string;
}

export const MyApp: React.FC<{}> = () => {
  const initialValues: MyFormValues = { firstName: '' };
  return (
    <div>
      <h1>My Example</h1>
      <Formik
        initialValues={initialValues}
        onSubmit={(values, actions) => {
          console.log({ values, actions });
          alert(JSON.stringify(values, null, 2));
          actions.setSubmitting(false);
        }}
      > …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs next.js formik

25
推荐指数
4
解决办法
3万
查看次数

标签 统计

formik ×1

next.js ×1

reactjs ×1

typescript ×1