@@ -249,9 +249,9 @@ result.isLoading
249249
250250``` jsx
251251// 실제 예제
252- const getAllSuperHero = useCallback ( () => {
253- return axios .get (" http://localhost:4000/superheroes" );
254- }, []) ;
252+ const getAllSuperHero = async () => {
253+ return await axios .get (" http://localhost:4000/superheroes" );
254+ };
255255
256256const { data , isLoading } = useQuery ([" super-heroes" ], getAllSuperHero);
257257```
@@ -264,10 +264,10 @@ const { data, isLoading } = useQuery(["super-heroes"], getAllSuperHero);
264264
265265``` jsx
266266// (1)
267- const getSuperHero = ({ queryKey }: any ) => {
267+ const getSuperHero = async ({ queryKey }: any ) => {
268268 const heroId = queryKey[1 ]; // queryKey: ['super-hero', '3']
269269
270- return axios .get (` http://localhost:4000/superheroes/${ heroId} ` );
270+ return await axios .get (` http://localhost:4000/superheroes/${ heroId} ` );
271271};
272272
273273const useSuperHeroData = (heroId : string ) => {
@@ -289,8 +289,8 @@ const useSuperHeroData = (heroId: string) => {
289289
290290``` jsx
291291// (2)
292- const getSuperHero = (heroId : string ) => {
293- return axios .get (` http://localhost:4000/superheroes/${ heroId} ` );
292+ const getSuperHero = async (heroId : string ) => {
293+ return await axios .get (` http://localhost:4000/superheroes/${ heroId} ` );
294294};
295295
296296const useSuperHeroData = (heroId : string ) => {
@@ -607,8 +607,10 @@ return (
607607[목차 이동](#주요-컨셉-및-가이드-목차)
608608
609609` ` ` jsx
610- const fetchColors = (pageNum : number ) => {
611- return axios .get (` http://localhost:4000/colors?_limit=2&_page=${ pageNum} ` );
610+ const fetchColors = async (pageNum : number ) => {
611+ return await axios .get (
612+ ` http://localhost:4000/colors?_limit=2&_page=${ pageNum} `
613+ );
612614};
613615
614616const { isLoading , isError , error , data , isFetching , isPreviousData } =
@@ -820,8 +822,10 @@ useEffect(() => {
820822import { useInfiniteQuery } from " react-query" ;
821823// import { useInfiniteQuery } from '@tanstack/react-query' v4
822824
823- const fetchColors = ({ pageParam = 1 }) => {
824- return axios .get (` http://localhost:4000/colors?_limit=2&_page=${ pageParam} ` );
825+ const fetchColors = async ({ pageParam = 1 }) => {
826+ return await axios .get (
827+ ` http://localhost:4000/colors?_limit=2&_page=${ pageParam} `
828+ );
825829};
826830
827831const InfiniteQueries = () => {
@@ -897,10 +901,10 @@ const { data } = useInfiniteQuery(["colors"], fetchColors, {
897901 * pageParam
898902 * { page, etc }
899903 */
900- const fetchColors = ({ pageParam }) => {
904+ const fetchColors = async ({ pageParam }) => {
901905 const { page = 1 , etc } = pageParam;
902906
903- return axios .get (` http://localhost:4000/colors?_limit=2&_page=${ page} ` );
907+ return await axios .get (` http://localhost:4000/colors?_limit=2&_page=${ page} ` );
904908};
905909` ` `
906910
@@ -1265,10 +1269,10 @@ function App() {
12651269
12661270` ` ` jsx
12671271// 기본 쿼리 함수
1268- const getSuperHero = ({ queryKey }: any ) => {
1272+ const getSuperHero = async ({ queryKey }: any ) => {
12691273 const heroId = queryKey[1 ];
12701274
1271- return axios .get (` http://localhost:4000/superheroes/${ heroId} ` );
1275+ return await axios .get (` http://localhost:4000/superheroes/${ heroId} ` );
12721276};
12731277
12741278const queryClient = new QueryClient ({
0 commit comments