Formik / 元素类型无效 - 得到“未定义”
Formik / Element Type Is Invalid - got " undefined "
我正在尝试将 Formik 用于 React Native。我基本上复制粘贴了对我不起作用的普通文档示例,并且没有找到任何其他相关示例来提供帮助。
https://formik.org/docs/guides/react-native
我刚刚也尝试使用功能组件:
import React, { useState, useRef } from 'react';
import {
Text, StyleSheet
} from 'react-native';
import { Formik} from "formik";
import { Card, Button, TextInput, View } from 'react-native-elements';
function AddActivityScreen() {
return(
<Formik
initialValues={{ email: '' }}
onSubmit={values => console.log(values)}
>
{({ handleChange, handleBlur, handleSubmit, values }) => (
<View>
<TextInput
onChangeText={handleChange('email')}
onBlur={handleBlur('email')}
value={values.email}
/>
<Button onPress={handleSubmit} title="Submit" />
</View>
)}
</Formik>
)
}
export default AddActivityScreen;
我一直有这个错误:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `Formik`.
我不明白 Formik 的问题是什么,因为我只是在执行文档中提供的代码示例。请有人帮忙
问题与 Formik 无关,而是与您的其他组件的导入有关
您正在从 react-native-elements 导入 TextInput 和 View,它们在该包中不存在,它们是 react-native 本身的一部分。
当您执行此操作并尝试渲染时,会出现上述错误。
像下面这样更改您的导入
import React, { useState, useRef } from 'react';
import {
Text, StyleSheet,TextInput, View
} from 'react-native';
import { Formik} from "formik";
import { Card, Button } from 'react-native-elements';
我正在尝试将 Formik 用于 React Native。我基本上复制粘贴了对我不起作用的普通文档示例,并且没有找到任何其他相关示例来提供帮助。 https://formik.org/docs/guides/react-native
我刚刚也尝试使用功能组件:
import React, { useState, useRef } from 'react';
import {
Text, StyleSheet
} from 'react-native';
import { Formik} from "formik";
import { Card, Button, TextInput, View } from 'react-native-elements';
function AddActivityScreen() {
return(
<Formik
initialValues={{ email: '' }}
onSubmit={values => console.log(values)}
>
{({ handleChange, handleBlur, handleSubmit, values }) => (
<View>
<TextInput
onChangeText={handleChange('email')}
onBlur={handleBlur('email')}
value={values.email}
/>
<Button onPress={handleSubmit} title="Submit" />
</View>
)}
</Formik>
)
}
export default AddActivityScreen;
我一直有这个错误:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `Formik`.
我不明白 Formik 的问题是什么,因为我只是在执行文档中提供的代码示例。请有人帮忙
问题与 Formik 无关,而是与您的其他组件的导入有关
您正在从 react-native-elements 导入 TextInput 和 View,它们在该包中不存在,它们是 react-native 本身的一部分。
当您执行此操作并尝试渲染时,会出现上述错误。
像下面这样更改您的导入
import React, { useState, useRef } from 'react';
import {
Text, StyleSheet,TextInput, View
} from 'react-native';
import { Formik} from "formik";
import { Card, Button } from 'react-native-elements';