代码之家  ›  专栏  ›  技术社区  ›  sudip

react native index.js和import react

  •  1
  • sudip  · 技术社区  · 7 年前

    我学的是本土反应。我的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”不在任何地方使用。那么,我为什么要把它进口到这里?如果我把它注释掉,那么我会得到一个错误“cant find variable:react”。 React Native需要它吗?如果是这样,那么为什么React Native没有导入它?背后有什么原因吗?

    我了解我在使用组件时正在app.js文件中导入“react”。

    谢谢您。

    我找到了答案。我忘记了我在index.js文件中使用了JSX,为此我需要导入react。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Aaron Brager    7 年前

    react包括JSX语法所需的内容。如果不导入React,则可以不使用JSX。

    推荐文章