React Native运行报错ReferenceError: TextInput is not defined如何解决?
问题修复方案
错误原因
ReferenceError: TextInput is not defined 报错的核心原因是:你在代码中使用了React Native内置的TextInput组件,但没有从react-native依赖包中提前导入该组件。
修复步骤
找到你代码中从react-native导入组件的行:
import { StyleSheet, Text, View } from 'react-native';
在导入列表中补充TextInput即可,修改后代码如下:
import { StyleSheet, Text, View, TextInput } from 'react-native';
完整修复后代码
import { StatusBar } from 'expo-status-bar'; import React from 'react'; import { StyleSheet, Text, View, TextInput } from 'react-native'; export default function App() { return ( <View style={styles.container}> <Text>Hello World</Text> <TextInput placeholder ="something"/> <StatusBar style="auto" /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, });
内容的提问来源于stack exchange,提问作者Khoi Le
相关产品推荐
相关产品推荐

