admin管理员组文章数量:1406974
I'm testing out using redux-observable
with a side-project and I'm running into this problem repeatedly: Uncaught TypeError: bineEpics: 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. 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 = bineEpics(
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')
);
I'm testing out using redux-observable
with a side-project and I'm running into this problem repeatedly: Uncaught TypeError: bineEpics: 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. 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 = bineEpics(
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')
);
Share
Improve this question
asked May 13, 2017 at 23:42
JoseJose
5,2408 gold badges29 silver badges50 bronze badges
1 Answer
Reset to default 10Your handleSearchEpic
epic is an arrow function with a block but does not actually return the stream.
Bad
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
Good
export const handleSearchEpic = action$ => {
return action$.ofType(SEARCH_CONTENT)
.mergeMap(action => axios.get(`...SOME_API_ENDPOINT`))
.map(res => returnSearchContent(res))
}
Implicit return?
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 mon 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?
bineEpics: one of the provided Epics "handleSearchEpic" does not return a stream. Double check you're not missing a return statement!
本文标签: javascriptEpic not returning stream in ReduxObservableStack Overflow
版权声明:本文标题:javascript - Epic not returning stream in Redux-Observable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745047017a2639429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论