use-http icon indicating copy to clipboard operation
use-http copied to clipboard

Reset state?

Open jakajancar opened this issue 3 years ago • 1 comments

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.

jakajancar avatar Jun 20 '21 21:06 jakajancar

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.

kirill-konshin avatar Jul 27 '22 22:07 kirill-konshin