首页 > 解决方案 > 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-native

解决方案


React 包含了 JSX 语法所必需的内容。如果不导入 React,就不能使用 JSX。


推荐阅读