Jos*_*ose 2 javascript rxjs redux-observable
我正在测试redux-observable与辅助项目一起使用,并且反复遇到此问题:Uncaught TypeError: combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
我已经在线参考了redux可观察的文档和其他一些示例,但是我无法确定可能缺少的内容。以下是我的行动和相关的史诗。
export const searchContent = query => {
return {
type: SEARCH_CONTENT,
query
}
}
const returnSearchContent = searchResults => {
return function(dispatch) {
dispatch({
type: RETURN_SEARCH_CONTENT,
searchResults
});
}
}
// Epics
export const handleSearchEpic = action$ => {
action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res))
}
export const rootEpic = combineEpics(
handleSearchEpic
);
Run Code Online (Sandbox Code Playgroud)
这是应用程序和存储配置的根目录:
const epicMiddleware = createEpicMiddleware(rootEpic);
const store = createStore(Reducer, applyMiddleware(epicMiddleware));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)
您的handleSearchEpic史诗是带有块的箭头函数,但实际上并未返回流。
export const handleSearchEpic = action$ => { // <-- start of block
// vvvvvvv missing return
action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res))
} // <-- end of block
Run Code Online (Sandbox Code Playgroud)
export const handleSearchEpic = action$ => {
return action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res))
}
Run Code Online (Sandbox Code Playgroud)
另外,您可以删除该块并使用隐式返回,这可能就是您想要做的事情?
export const handleSearchEpic = action$ => // <--- no block
action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res));
Run Code Online (Sandbox Code Playgroud)
一个非常常见的错误,这就是为什么我添加了您提供的错误消息的原因,但是它似乎并未使解决方案易于理解。有什么建议可以改善错误消息吗?
CombineEpics:提供的Epics“ handleSearchEpic”中的一个不返回流。仔细检查,您不会错过任何退货声明!
| 归档时间: |
|
| 查看次数: |
988 次 |
| 最近记录: |