score:1

function useRequestData(route){
  const [requestData, setRequestData] = useState(null);
  const [tagsData, setTagsData] = useState(null);
  useEffect(() => {
    fetch(route, {
      method: "POST",
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        "Access-Control-Allow-Origin": "*",
      },
      body: JSON.stringify(group),
    })
      .then(response => {
        return setRequestData(response.json());
      })
      .then(data => {
        console.log("request data", data);
        // debugger;
        setTagsData(data);
      });
  }, []);
  // return [loading, data]
  return [!requestData, requestData, tagsData];
}

function App(){
  const [loading, data, err] =  
  useRequestData("http://localhost:4996/getTagsFromWebsite");
  return loading ? "loading..." : data.foobar;
}

Related Query

More Query from same tag