ReactJS custom hook, called again depending on it's data

Viewed 205

I want to call a custom hook once again depending on it's value that returns.

Currently, I have this:

const { data } = useMaximumAmount();

React.useEffect(() => {
  if (data?.MaxAmount < 1) {
    // do something
  }
}, [data?.MaxAmount]);

But also that hook it returns an "error" so I could call it like this way:

const { data, error } = useMaximumAmount();

Now if "error" is true, I need to call the useMaximumAmount again in order to retrieve data again. That error is true sometimes because inside useMaximumAmount there's an API call that could fail or not.

Any idea?

Or maybe it's better to edit the hook and detects that the API call gives an error and make the call again before returning it's response?

0 Answers
Related