There's moreā€¦

When you write your action creator, it actually gets passed not only dispatch() but also the getState() function. This function can be used to access the current state value. We didn't use this, but, for example, you could do so for caching or other similar ideas. Our getRegions() function could be as follows, to detect whether you are requesting the same country's regions again:

// Source file: src/regionsApp/world.actions.js

export const getRegions2 = (country: string) => async (
dispatch,
getState
) => {
if (country === getState().currentCountry) {
console.log("Hey! You are getting the same country as before!");
}

if (country) {
.
.
. everything as earlier
.
.
}
};

In our case, we aren't doing anything other than logging a message, but you could use the received parameters plus the current state contents in order to do some more complex logic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.174.168