You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 12:54:03