didierfranc / didierfranc/react-waterfall

Chaining actions and waiting for state updates?

Open
#86 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.3k
Forks
73
PR merge metrics
No merged PRs in 30d

Description

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.

```js
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.

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.