Created
August 16, 2020 18:38
-
-
Save simicd/99099ce6b0a0d5e5682adfa1843abcc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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