react-native - React 原生 index.js 并导入 react
问题描述
我正在学习本机反应。我的 index.js 文件如下所示:
import React from 'react';
import { AppRegistry } from 'react-native';
import { Provider } from 'react-redux';
import App from './App';
import configureStore from './src/store/configureStore';
const store = configureStore();
const RNRedux = () => (
<Provider store={store}>
<App />
</Provider>
);
AppRegistry.registerComponent('redux1', () => RNRedux);
现在,我的问题是:“React”没有在任何地方使用。那么,我为什么要在这里导入它?如果我将其注释掉,那么我会收到一个错误“找不到变量:React”。react native 需要吗?如果是这样,那为什么 react native 没有导入呢?这背后有什么原因吗?
我知道我在使用组件时在我的 App.js 文件中导入“react”。
谢谢你。
** 我找到了答案。我忘记了我在 index.js 文件中使用了 JSX,为此我需要导入 react。
解决方案
React 包含了 JSX 语法所必需的内容。如果不导入 React,就不能使用 JSX。
推荐阅读
- sql - 需要帮助以使用 Vertica 中的特定分隔符函数捕获部分字符串值
- java - Java 错误(错误:找不到符号)
- javascript - 我想问一个关于javascript image src的问题
- javascript - 从 API 获取数据后在 VueJS 中显示数据数组的长度
- c - 如何在 Espressif IDF Eclipse 项目的不同源文件中包含 FreeRTOS 头文件
- ios - iOS 图表显示 yAxis 值是 X 的倍数
- ruby-on-rails - Rails 解密时 MessageEncryptor::InvalidMessage 出错
- r - 参数未在函数中重新确定
- python - 如果值为yes,则按多列分组?
- postgresql - 使用 PMM2 进行 RDS 监控,Postgres 缺少主机指标