Rematch: 1.x to 2.x migration effect does not return promise

Created on 25 Sep 2020  路  6Comments  路  Source: rematch/rematch

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.

needs-repo question

All 6 comments

Shouldn't it be?

const mapDispatch = (dispatch) => ({
   first: dispatch.model.first, 
   second: dispatch.mode.second
})

with model name specified and without ()

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xialvjun picture xialvjun  路  6Comments

kertul picture kertul  路  4Comments

ShMcK picture ShMcK  路  4Comments

777PolarFox777 picture 777PolarFox777  路  3Comments

linonetwo picture linonetwo  路  5Comments