Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { useCallback, useEffect, useState } from 'react';
- const useChangeItem = ({url, body}) => {
- const [data, setData] = useState(null)
- const fetchData = useCallback( async () => {
- const fetchResponse = await fetch(url, {
- method: "PUT",
- headers: {
- "Content-Type":"application/json",
- },
- body: JSON.stringify(body)
- });
- const jsonData = await fetchResponse.json();
- setData(jsonData);
- },[body, url]);
- useEffect(()=>{
- fetchData();
- },[fetchData])
- return data;
- }
- export default useChangeItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement