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

React Native切换页面时提示‘Button is not defined’错误求助

问题原因

你遇到的"Button is not defined"错误并非来自Home.js,而是出在Game.js组件中。当点击按钮触发页面跳转时,App会尝试加载Game组件,如果Game.js里使用了Button但没有正确导入,就会抛出这个错误。换成console.log后不会跳转加载Game组件,所以错误消失。

解决步骤

  1. 打开你的Game.js文件,检查是否使用了<Button>组件但未导入。
  2. 在Game.js的顶部添加Button的导入语句:
// 方式一:单独导入Button
import { Button } from 'react-native';

// 方式二:和其他组件一起导入(推荐)
import { View, Text, Button } from 'react-native';

内容的提问来源于stack exchange,提问作者sandy b

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 01:10:54