You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
541 B
21 lines
541 B
import { useCallback, useEffect, useRef, useState } from 'react' |
|
import { useAppContext } from '../../contexts/AppContext' |
|
|
|
export const useGet = <T>(path: string) => { |
|
const appContext = useRef(useAppContext()) |
|
const [data, setData] = useState<T | null>(null) |
|
|
|
const get = useCallback(async () => { |
|
const data = await appContext.current.get<T>(path) |
|
if (!data) return |
|
|
|
setData(data) |
|
}, [path]) |
|
|
|
useEffect(() => { |
|
get() |
|
// eslint-disable-next-line react-hooks/exhaustive-deps |
|
}, []) |
|
|
|
return { data, get } |
|
}
|
|
|