Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useCallback, useEffect, useState } from 'react';
  2.  
  3. const useChangeItem = ({url, body}) => {
  4.  
  5.     const [data, setData] = useState(null)
  6.  
  7.     const fetchData = useCallback( async () => {
  8.         const fetchResponse = await fetch(url, {
  9.             method: "PUT",
  10.             headers: {
  11.                 "Content-Type":"application/json",
  12.             },
  13.             body: JSON.stringify(body)
  14.         });
  15.        
  16.         const jsonData = await fetchResponse.json();
  17.         setData(jsonData);
  18.     },[body, url]);
  19.    
  20.     useEffect(()=>{
  21.         fetchData();
  22.     },[fetchData])
  23.  
  24.     return data;
  25. }
  26.  
  27. export default useChangeItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement