Advertisement
Guest User

Untitled

a guest
Nov 21st, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useState } from "react";
  2.  
  3. const useFetch = async (url)=>{
  4.  
  5.     const [data, setData] = useState(null);
  6.  
  7.     const response = await fetch(url,{
  8.         method: "GET",
  9.         headers: {
  10.         "Content-Type":"application/json",
  11.         }
  12.     })
  13.  
  14.     setData(await response.json());
  15.  
  16.     console.log({data});
  17.  
  18.     if(response.status === 200){
  19.         return data
  20.     }
  21. }
  22.  
  23. export default useFetch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement