i've written a custom hook to help me not repeat code for some fetch calls. it looks like this:
export const useCustomQuery = ({ endpoint, body, dataPoint }: args) => {
const [data, setData] = useState()
useEffect(() => {
fetch(`http://localhost:4000/${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body,
})
.then((res) => res.json())
.then((res) => {
if (dataPoint) {
setData(JSON.parse(res.data[dataPoint]))
}
})
}, [endpoint, body, dataPoint])
return { data }
}
but I'm getting some TS errors complaining about the type of data. is it possible to pass in the type as an argument as it might be different for each component that calls the hook? or what is the best way to approach this?