我對react-native & Viro-react平臺非常陌生。目前,我正在為我的畢業設計開發一個AR/VR應用。在該專案中,我需要應用redux功能,并為我的整個應用程式實作一個共同的存盤。我已經正確地創建了store/index.js(存盤),store/reducer/index.js(根reducer)& store/reducer/initial_Reducer.js,store/actions/initial_Action.js。下面是它們。
store/index.js (store)
從'./reducers'匯入rootReducer。
從'redux'中匯入{createStore}。
const store = createStore(rootReducer);
輸出默認的存盤。
store/reducer/index.js (root reducer)
從'./initial_Reducer'匯入 initial_Reducer。
從'redux'中匯入 { combineReducers }。
const rootReducer = combineReducers({
initial_Reducer: initial_Reducer,
});
輸出默認的rootReducer。
store/reducer/initial_Reducer.js
const initial_Reducer = (state = {store:true}, action) => {
console.log("Initial Reducer...")。
switch (action.type) {
case 'initialize': {
回傳狀態。
}
默認情況下。
回傳狀態。
}
}
export default initial_Reducer;
store/actions/initial_Action.js
export const initializeStore = () => {
console.log("Initial Action.")。
回傳 {
type: 'initialize'
}
}
當我試圖將存盤應用于with標簽時,它給了我以下錯誤。
React未被定義
我的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
//下面這行是與TestBed App一起使用所必需的
AppRegistry.registerComponent('ViroSample', () =>
<提供者 store={store} >
<App />
</Provider>
);
index.android.js
import { AppRegistry } from 'react-native';
從'./App.js'中匯入App。
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
//下面這行是與TestBed應用一起使用所必需的
AppRegistry.registerComponent('ViroSample', () =>
<提供者 store={store} >
<App />
</Provider>
);
uj5u.com熱心網友回復:
你應該在index.android.js和index.js
從 "react "匯入React。
uj5u.com熱心網友回復:
在所有包含JSX的檔案中添加import 'react';,并且不利用React explicit.
在你的例子中,這是index.android.js和index.js,并將這些檔案從*.js重命名為*.jsx.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/326328.html
標籤:
上一篇:AppEngine部署失敗并顯示“致命:無法訪問‘https://gopkg.in/yaml.v3/’:服務器證書驗證失敗。”
