[英]Epic not returning stream in Redux-Observable
I'm testing out using redux-observable
with a side-project and I'm running into this problem repeatedly: Uncaught TypeError: combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
我正在测试使用带有side-project的
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!
这个问题: Uncaught TypeError: combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
Uncaught TypeError: combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
I've referenced the redux observable docs and several other examples online but I can't identify what I might be missing. 我在网上引用了redux可观察文档和其他几个例子,但我无法确定我可能缺少的内容。 Below are my actions and the epic in question.
以下是我的行为和有问题的史诗。
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
);
Here is the root of the application and the store config: 这是应用程序的根和商店配置:
const epicMiddleware = createEpicMiddleware(rootEpic);
const store = createStore(Reducer, applyMiddleware(epicMiddleware));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
Your handleSearchEpic
epic is an arrow function with a block but does not actually return the stream. 你的
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
export const handleSearchEpic = action$ => {
return action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res))
}
Alternatively, you can remove the block and use an implicit return, which may be what you meant to do? 或者,您可以删除块并使用隐式返回,这可能是您的意图吗?
export const handleSearchEpic = action$ => // <--- no block
action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res));
A very common mistake, which is why I added the error message you provided, but it didn't seem to make the solution understandable. 一个非常常见的错误,这就是为什么我添加了您提供的错误消息,但它似乎并没有使解决方案可理解。 Any suggestions how I can improve the error message?
有关如何改进错误消息的任何建议吗?
combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream.
combineEpics:提供的Epics之一“handleSearchEpic”不返回流。 Double check you're not missing a return statement!
仔细检查你没有错过退货声明!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.