File tree Expand file tree Collapse file tree 2 files changed +15
-26
lines changed
Expand file tree Collapse file tree 2 files changed +15
-26
lines changed Original file line number Diff line number Diff line change 1- //import React, {useState, useEffect} from 'react';
21import React from 'react' ;
32
43import { useFetchGifs } from '../hooks/useFetchGifs' ;
54
6- //import GifGridItem from './GifGridItem';
7- //import { getGifs } from '../helpers';
5+ import GifGridItem from './GifGridItem' ;
86
97const GifGrid = ( { category} ) => {
10- //const [gifs, setGifs] = useState([]);
11-
12- const { loading} = useFetchGifs ( ) ;
13-
14- //useEffect(() => {
15- // getGifs(category)
16- // .then(setGifs)
17- //}, [category]);
8+ const { data : gifs , loading} = useFetchGifs ( category ) ;
189
1910 return (
2011 < div className = "card-grid" >
2112 < h3 > { category } </ h3 >
13+ { loading && < p > Loading</ p > }
2214 {
23- loading ?
24- 'loading...'
25- :
26- 'show'
27- }
28- { /*
2915 gifs . map ( gif => (
3016 < GifGridItem
3117 key = { gif . id }
3218 { ...gif }
3319 /> )
3420 )
35- */ }
21+ }
3622 </ div >
3723 ) ;
3824}
Original file line number Diff line number Diff line change 1- import { useState } from 'react' ;
1+ import { useState , useEffect } from 'react' ;
22
3- export const useFetchGifs = ( ) => {
3+ import { getGifs } from '../helpers' ;
4+
5+ export const useFetchGifs = category => {
46 const [ state , setState ] = useState ( {
57 data : [ ] ,
68 loading : true
79 } ) ;
810
9- setTimeout ( ( ) => {
10- setState ( {
11- ...state ,
12- loading : false
13- } )
14- } , 3000 ) ;
11+ useEffect ( ( ) => {
12+ getGifs ( category )
13+ . then ( gifs => setState ( {
14+ data : gifs ,
15+ loading : false
16+ } ) )
17+ } , [ category ] ) ;
1518
1619 return state ; // { data: [], loading: true }
1720}
You can’t perform that action at this time.
0 commit comments