Epic 未在 Redux-Observable 中返回流
Epic not returning stream in Redux-Observable
我正在使用 redux-observable
和 side-project 进行测试,我 运行 反复遇到这个问题:Uncaught TypeError: combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
我已经在网上参考了 redux observable 文档和其他几个示例,但我无法确定我可能遗漏了什么。以下是我的行为和有问题的史诗。
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
);
这是应用程序的根目录和商店配置:
const epicMiddleware = createEpicMiddleware(rootEpic);
const store = createStore(Reducer, applyMiddleware(epicMiddleware));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
您的 handleSearchEpic
史诗是一个箭头函数 带有块 但实际上 return 流。
不好
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))
}
隐式 return?
或者,您可以删除块并使用隐式 return,这可能正是您想要做的?
export const handleSearchEpic = action$ => // <--- no block
action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res));
一个非常常见的错误,这就是为什么我添加了您提供的错误消息,但它似乎并没有使解决方案易于理解。有什么改进错误消息的建议吗?
combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
我正在使用 redux-observable
和 side-project 进行测试,我 运行 反复遇到这个问题:Uncaught TypeError: combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
我已经在网上参考了 redux observable 文档和其他几个示例,但我无法确定我可能遗漏了什么。以下是我的行为和有问题的史诗。
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
);
这是应用程序的根目录和商店配置:
const epicMiddleware = createEpicMiddleware(rootEpic);
const store = createStore(Reducer, applyMiddleware(epicMiddleware));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
您的 handleSearchEpic
史诗是一个箭头函数 带有块 但实际上 return 流。
不好
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))
}
隐式 return?
或者,您可以删除块并使用隐式 return,这可能正是您想要做的?
export const handleSearchEpic = action$ => // <--- no block
action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res));
一个非常常见的错误,这就是为什么我添加了您提供的错误消息,但它似乎并没有使解决方案易于理解。有什么改进错误消息的建议吗?
combineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!