This file contains 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
{"lastUpload":"2020-06-09T07:29:00.207Z","extensionVersion":"v3.4.3"} |
This file contains 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
import { useEffect } from "react"; | |
export function useRelativeClick(ref, callback: (inside: boolean) => any) { | |
function handleClickOutside(event) { | |
if (ref.current) { | |
const insideClick = ref.current.contains(event.target) | |
callback(insideClick) | |
} | |
} |
This file contains 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
export const useFetch = (url) => { | |
const [data, setData] = useState(null); | |
const [loading, setLoading] = useState(true); | |
const [error, setError] = useState(null); | |
useEffect(() => { | |
const fetchData = async () => { | |
setLoading(true); | |
setError(null); | |
try { |
This file contains 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
import { useEffect, useState } from "react" | |
/** | |
* Example usage: | |
const App = () => { | |
const { data, error, loading } = useFetch<any>("https://jsonplaceholder.typicode.com/posts") | |
if (loading) return <div>Loading...</div> | |
if (error) return <div>Error</div> | |
if (data) <div>{JSON.stringify(data)}</div> | |
} |