我正在学习 React Native。我的 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。
关于react-native - React 原生index.js 并导入react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54268806/