我试图将simpreWebRTC集成到React项目中,但是库有自己的redux存储库,文档显示如下:
“提供的createStore函数使基本的Redux存储对于开始操作非常有用。如果您想要创建自己的存储库,请从‘@and乃至/simplewebrtc’导入reducer,并确保将其分配给状态对象顶层的simplewebrtc。”
我试过几种方法,但没有用,知道吗?我在这里错过了什么?谢谢
这是我到目前为止掌握的代码:
store.js
import {createStore, applyMiddleware} from 'redux'
import rootReducer from './reducers/index'
import thunk from 'redux-thunk';
export default createStore(rootReducer, applyMiddleware(thunk));
const store = createStore(rootReducer);
console.log(store.getState());./减速器/索引.
import {combineReducers} from 'redux'
import {reducer as simplewertc} from '@andyet/simplewebrtc'
import liveRoomReducer from './liveRoomReducer'
export default combineReducers({simplewertc, liveRoomReducer});./减速器/liveRoomReducer.js
const initialState = {
test : 'test'
};
export default function liveRoomReducer(state=initialState, action) {
return state;
};我正在控制台中记录存储状态,并在其上显示simplewebrtc:

并且仍然显示了这个错误:

发布于 2018-12-25 21:18:38
使用thunk中间件创建自己的商店并使用combineReducers应该可以做到这一点:
import {combineReducers} from 'redux';
import {reducer as simplewebrtc} from '@andyet/simplewebrtc';
import reducer1 from 'path/to/your/reducer1';
import reducer2 from 'path/to/your/reducer2';
export default combineReducers({simplewebrtc, reducer1 , reducer2});如果这不适用于您,请提供什么错误显示,如果有的话和一些示例代码,如何创建您的redux存储和根还原器。
编辑:在看到用代码更新的问题之后,我们发现在导入还原器时出现了一个错误。
https://stackoverflow.com/questions/53924526
复制相似问题