Skip to content

Instantly share code, notes, and snippets.

@StephenDRoberts
Last active August 21, 2020 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenDRoberts/9d2596578fa92bebd1a2d8d62c88cbd7 to your computer and use it in GitHub Desktop.
Save StephenDRoberts/9d2596578fa92bebd1a2d8d62c88cbd7 to your computer and use it in GitHub Desktop.
Query hook to fetch data
import { useState, useEffect } from 'react';
import { DailyPrice, APIResponse } from '../types/types';
import { get } from '../fetchers/fetchers';
export const useGetDailyPrices = () => {
const [data, setData] = useState<DailyPrice[]>([]);
const getData = async () => {
const { results } = await get<APIResponse>('./data/DUMMY_DATA.json');
setData(results)
}
useEffect(() => {
getData()
}, [])
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment