-1

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

商店/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;

存储/操作/initial_Action.js

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

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

React is not defined

请检查此屏幕截图

我的 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>
);
4

2 回答 2

0

你应该在这两个文件中导入 Reactindex.android.js并且index.js

import React from "react";
于 2021-09-21T06:21:26.453 回答
0

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

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

于 2021-09-21T06:24:47.960 回答