2 simple ways to call an action on state change
Scenario
I would like to refresh the list of available states based on the selected country.
1. useEffect
One of the parameters of this function is the array of values that works as a listener.
The useEffect will be performed only on the first render and when the value of selectedCountry changes.
It is a great place for this scenario, you have just to be careful to not using it much and lost control of the requests. Checking the network tab is a great place to see if you are not calling a request multiple times.
2. Simply calling a function
I feel comfortable using this simple approach because I know exactly who is triggering the action
0 view