title: state is not getting updated using react hooks?
body: <p>I have created one custom hook for the Api call. Am trying to set one flag value to be false, whenever the api call is happening. Once i get the response, the flag should changed to false. I have dispatching the action inside the api call, but i couldn't able to update the state value. </p>
  
  <pre><code>import { useEffect, useReducer } from "react";
  import fetch from "axios";
  
  const useApiHook = (url, reducer) =&gt; {
      const [state, dispatch] = useReducer(reducer, { loading: false });
  
      useEffect(() =&gt; {
          fetch(url)
              .then(dispatch({ type: "fetching", loading: true }))
              .then(res =&gt; res.data)
              .then(data =&gt; dispatch({ type: "success", loading: false, data }))
              .catch(err =&gt; dispatch({ type: "fail", loading: false, err }));
      }, [url]);
  
      return state;
  };
  }
  const Reducer = (state, action) =&gt; {
      const { url, data, err } = action;
      const currentState = state[url];
      console.log("action", action);
      console.log("state", state.loading);
      switch (action.type) {
          case "fetching":
              return {
                  ...state,
                  [url]: { ...currentState, loading: action.loading }
              };
          case "success":
              return {
                  ...state,
                  [url]: { ...currentState, loading: action.loading, data }
              };
          case "fail":
              return {
                  ...state,
                  [url]: { ...currentState, loading: action.loading, err }
              };
          default:
              return state;
      }
  };
  const Comp = () =&gt; {
      const url = "https://randomuser.me/api/";
      const sample = useApiHook(url, Reducer);
  }
  </code></pre>
  
  <p>can any one help me out in updating the state?</p>