Skip to content
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

Chaining actions and waiting for state updates? #86

Open
SaphuA opened this issue Oct 18, 2018 · 1 comment
Open

Chaining actions and waiting for state updates? #86

SaphuA opened this issue Oct 18, 2018 · 1 comment

Comments

@SaphuA
Copy link

SaphuA commented Oct 18, 2018

What is the recommended way to chain actions where the second action is dependent on the first action to update the state?

For example. Selecting a country in a dropdown and then fetch a list of cities once one is selected.

This obviously doesn't work.

    selectCountry: (state, actions, country) => {
        actions.readCities();
        return { selectedCountry: country };
    },
    readCities: (state, actions) => {
        state.selectedCountry; // etc...
    }

The workaround I use now is to make country an optional argument of readCities, but I feel this is making the code needlessly complex. Especially with larger/complexer stores/actions.

    selectCountry: (state, actions, country) => {
        actions.readCities(country);
        return { selectedCountry: country };
    },
    readCities: (state, actions, country) => {
        country = country || state.selectedCountry; // etc...
    }
@artdevgame
Copy link

artdevgame commented May 11, 2020

I came here with a similar question. Did you solve this? @didierfranc can you offer any insight?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants