【问题标题】:"React is not defined"“未定义反应”
【发布时间】:2021-09-21 06:11:07
【问题描述】:

我对 react-native 和 Viro-react 平台非常陌生。目前,我正在为我最后一年的项目开发一个 AR/VR 应用程序。在那个项目中,我需要应用 redux 功能并为我的整个应用程序实现一个公共存储。我已经正确地创建了store/index.js(存储)、store/reducer/index.js(根减速器)和store/reducer/initial_Reducer.jsstore/actions/initial_Action.js。以下是他们。

store/index.js(存储)

import rootReducer from './reducers';
import {createStore} from 'redux';

const store = createStore(rootReducer);

export default store;

store/reducer/index.js(根减速器)

import initial_Reducer from './initial_Reducer';
import { combineReducers } from 'redux';

const rootReducer = combineReducers({
    initial_Reducer: initial_Reducer,
});

export default rootReducer;

存储/reducer/initial_Reducer.js

const initial_Reducer = (state = {store:true}, action) => {
    console.log("Initial Reducer..");
    switch (action.type) {
        case 'initialize': {
            return state;
        }
        default:
            return state;
    }
}

export default initial_Reducer;

store/actions/initial_Action.js

export const initializeStore = () => {
    console.log("Initial Action..");
    return {
        type: 'initialize'
    }
}

当我尝试将商店应用到 with 标签时,它给了我以下错误。

React is not defined

Please check this screenshot

我的 index.js & index.android.js 如下。

index.js

import { AppRegistry } from 'react-native';
import App from './App.js';

import store from './store/index'; //importing redux store config from store/index.js
import { Provider } from 'react-redux/src'; //importing binding layer from reac-redux

// The below line is necessary for use with the TestBed App
AppRegistry.registerComponent('ViroSample', () =>
    <Provider store={store} >
        <App />
    </Provider>
);

index.android.js

import { AppRegistry } from 'react-native';
import App from './App.js';

import store from './store/index'; //importing redux store config from store/index.js
import { Provider } from 'react-redux/src' //importing binding layer from reac-redux

// The below line is necessary for use with the TestBed App
AppRegistry.registerComponent('ViroSample', () =>
    <Provider store={store} >
        <App />
    </Provider>
);

【问题讨论】:

    标签: react-native redux react-redux viro-react


    【解决方案1】:

    您应该在 index.android.jsindex.js 两个文件中导入 React

    import React from "react";
    

    【讨论】:

      【解决方案2】:

      在所有包含 JSX 的文件中添加 import 'react';,不要使用 React 显式。

      在您的情况下,这是 index.android.jsindex.js 并将这些文件从 *.js 重命名为 *.jsx。

      【讨论】:

        猜你喜欢
        • 2014-09-18
        • 2018-07-06
        • 2021-09-20
        • 2018-05-20
        • 2019-04-27
        • 2017-12-21
        • 1970-01-01
        • 1970-01-01
        • 2023-03-31
        相关资源
        最近更新 更多