use-axios-react
use-axios-react copied to clipboard
Feature request
Hi, Sergey.
In "useRequestCallback" its state is "execCount: 0,", but when an error occurs it is reset. In "useEffect" the code does not increment "execCount".
try {
const response = await axiosInstance(requestConfig);
setState({ ...state, loading: false, response, data: response.data });
} catch (error) {
setState({ ...state, loading: false, error });
}
Suggestion:
try {
const response = await axiosInstance(requestConfig);
setState({ ...state, loading: false, response, data: response.data });
} catch (error) {
if (state.execCount > 3) { // attempt number = 3
setState({ ...state, loading: false, execCount: 0, error });
} else {
setState({ ...state, loading: false, execCount: (state.execCount + 1), error });
}
}
Thanks.