Answers for "react useeffect is cancelled"

0

react useeffect is cancelled

useEffect(() => {
    const abortController = new AbortController();

    const fetchData = async () => {
      dispatch(requestStarted());

      try {
        fetch(url, { signal: abortController.signal });

        // code omitted for brevity

        dispatch(requestSuccessful({ data }));
      } catch (e) {
        dispatch(requestFailed({ error: e.message }));
      }
    };

    fetchData();

    return () => {
      abortController.abort();
    };
  }, [url]);
Posted by: Guest on June-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language