Describe the bug
In v2.0 the effect function does not return a promise.
In version 1.x I have this code that works fine.
model.js
effects: (dispatch) => ({
async first(payload, state) {
await ...
},
async second(payload, state) {
await ...
}
})
component.js
useEffect(() => {
first().then(() => {
second()
}
})
const mapDispatch = (dispatch) => ({
first: dispatch.first(),
second: dispatch.second()
})
In v2.x it complains that first.then is not a function.
To Reproduce
Try the code above
Expected behavior
I want to be able execute the second effect after the first one succeeded.
Shouldn't it be?
const mapDispatch = (dispatch) => ({
first: dispatch.model.first,
second: dispatch.mode.second
})
with model name specified and without ()
Please check example:
https://github.com/saraivinha85/rematch-next-test
reducers are not promises, if you use effects you will get that wanted promise,
I'll create a pull request to your codebase with some best practices later tonight
https://github.com/saraivinha85/rematch-next-test/pull/1/files @saraivinha85 here you have mate
Thanks for the explanation and example.
But can you tell me why my example worked with version 1.x?
Probably in version 1.x reducers were also promises, but that's not correct