use-http
use-http copied to clipboard
Reset state?
It would be nice if there was a way to reset the state (clear the response, error) when using manually triggered fetches. For example, if using useFetch
for login, would be nice to clear the error if the user starts to make changes to the login form.
Came here with the same issue, there's no way to clear the error, even cache.clear()
does not work...
So far I came up with following:
const {loading, error: httpError, post, cache, abort, data } = useFetch(...);
const [error, setError] = useState(httpError);
useEffect(() => {
setError(httpError);
}, [httpError]);
// and then
cache.clear();
setError(null);
But this is soooo awkward.