Skip to content

Instantly share code, notes, and snippets.

@simicd
Created August 16, 2020 18:38
Show Gist options
  • Save simicd/99099ce6b0a0d5e5682adfa1843abcc6 to your computer and use it in GitHub Desktop.
Save simicd/99099ce6b0a0d5e5682adfa1843abcc6 to your computer and use it in GitHub Desktop.
// useFetch.ts
import { useState, useEffect } from "react";
// ..
export const useFetch = ({ url, init }: RequestProps) => {
// ...
// Turn objects into strings for useCallback & useEffect dependencies
const [stringifiedUrl, stringifiedInit] = [JSON.stringify(url), JSON.stringify(init)];
useEffect(() => {
// ...
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stringifiedUrl, stringifiedInit]);
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment