-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store.dispatch(...).then is not a function #1251
Comments
I also tested with the action of the async example and it works:
So I don't really understand what is going on. Could someone explain me what are the requirements for a return function in async action? My final goal is to use a Meteor async method but I get the same error.
|
Dispatch will just return whatever you return from that function. If you return If you'd like, you can always return Promises for consistency. Redux doesn't enforce that, it is completely up to you what to return from thunks. There is no way Redux could've figured out you are waiting for an interval unless you explicitly create a Promise for it and return it. const delay = (ms) => new Promise(resolve =>
setTimeout(resolve, ms)
);
export const fetchObjects = () => {
return dispatch => {
dispatch(requestMapObjectsAction());
return delay(2000).then(() => {
dispatch({
type: RECEIVE_MAP_OBJECTS,
objects: {'id':'56789', 'id':'567Zdz'},
receivedAt: Date.now()
})
});
}
} |
I am having problem using redux-saga, I am trying to navigation from a child component:
I get this error: can someone help, thanx |
@yasir-netlinks : |
I'm not challenging you, @dagatsoin, but I suppose According to Redux' doc, the data flow is meant to be a strict unidirectional data flow. If you put |
@Hiroki1116 : You can only do function fetchData() {
return (dispatch) => {
return fetch("/someData")
.then(response => response.json())
.then(data => dispatch(loadData(data))
}
};
// elsewhere
dispatch(fetchData())
.then() => {
// do something now that the async call has resolved
}); This can be a useful capability, and is not going against Redux's unidirectional data flow. For more info, see the articles in the Redux Side Effects section of my links list. |
Thanks for your info. Of course, For example...
If As long as Correct me if I'm wrong! |
@Hiroki1116 : Two thoughts. First, you're worrying about the data flow aspect way too much. The important aspect is dispatched action -> reducer -> subscribers -> UI updates. Async stuff happens separate from that (or, alternately, can be what triggers the dispatched action in the first place). Second, in that particular snippet, But seriously, don't worry about it :) |
@Hiroki1116 I understand your concerns and I agree with @markerikson I had the Un-intuitively, my conclusion is that the possibility of returning something from the dispatch enforces the separation of concern principle.
Still, the data flow is respected. In addition I would argue that the respect of the unidirectional data flow is considered OUTSIDE
PS: by the way I had not thanks @gaearon for his response! Thanks you :) |
Thank you for your thoughts, @markerikson & @dagatsoin ! |
Hi,
I am learning advanced redux part of the doc. I use Meteor.
I have a error at the Async part
store.dispatch(...).then is not a function
Here is my entry point code:
and my fetchObjects action:
Could this be related to #1240 ? EDIT: No it does not.
The text was updated successfully, but these errors were encountered: