almost mvp
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useAppContext } from '../../contexts/AppContext'
|
||||
|
||||
export const useGet = <T>(path: string) => {
|
||||
type Config = {
|
||||
mode: 'list'
|
||||
}
|
||||
|
||||
export const useGet = <T>(path: string, config?: Config) => {
|
||||
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
|
||||
// @ts-ignore
|
||||
setData(data.results)
|
||||
}, [path])
|
||||
if (config?.mode === 'list') {
|
||||
// @ts-ignore
|
||||
setData(data.results)
|
||||
} else {
|
||||
setData(data)
|
||||
}
|
||||
}, [path, config])
|
||||
|
||||
useEffect(() => {
|
||||
get()
|
||||
|
||||
Reference in New Issue
Block a user