Is it good practice to chain useEffect hooks?

Viewed 701

Since there is no setState callback using react hooks I have to use an useEffect hook with the state in its dependency array as a callback function for setting the state.

So I often find myself chaining some useEffects to set states, wait until they were set, and then do some actions with it. This seems not as the correct way for me.

Here is an Example:

const url = useLocation();
 
useEffect(() => {
  // Do some stuff related to URL
  // ...
  // after processing the url params i set a config object as a state
  setConfig();
}, [url.search]);
 
useEffect(() => {
  // Fetch some data with the config 
  // ...
  // after data fetching is done
  setData([]);
}, [config]);
 
useEffect(() => {
  // process my fetched data 
}, [data]);

Is this the correct way to do it? Or is there a better approach?

0 Answers
Related