@@ -34,35 +34,36 @@ const Header = () => {
3434 } ;
3535
3636 // getting all wishlist items by user id
37- const getWishlistByUserId = useCallback ( async ( id : string ) => {
38-
39- const response = await fetch ( `http://localhost:3001/api/wishlist/${ id } ` , {
40- cache : 'no-store' ,
41- } ) ;
42- const wishlist = await response . json ( ) ;
43- const productArray : {
44- id : string ;
45- title : string ;
46- price : number ;
47- image : string ;
48- slug : string ;
49- stockAvailabillity : number ;
50- } [ ] = [ ] ;
51-
52- wishlist . map ( ( item : any ) =>
53- productArray . push ( {
54- id : item ?. product ?. id ,
55- title : item ?. product ?. title ,
56- price : item ?. product ?. price ,
57- image : item ?. product ?. mainImage ,
58- slug : item ?. product ?. slug ,
59- stockAvailabillity : item ?. product ?. inStock ,
60- } ) ,
61- ) ;
37+ const getWishlistByUserId = useCallback (
38+ async ( id : string ) => {
39+ const response = await fetch ( `http://localhost:3001/api/wishlist/${ id } ` , {
40+ cache : 'no-store' ,
41+ } ) ;
42+ const wishlist = await response . json ( ) ;
43+ const productArray : {
44+ id : string ;
45+ title : string ;
46+ price : number ;
47+ image : string ;
48+ slug : string ;
49+ stockAvailabillity : number ;
50+ } [ ] = [ ] ;
6251
63- setWishlist ( productArray ) ;
52+ wishlist . map ( ( item : any ) =>
53+ productArray . push ( {
54+ id : item ?. product ?. id ,
55+ title : item ?. product ?. title ,
56+ price : item ?. product ?. price ,
57+ image : item ?. product ?. mainImage ,
58+ slug : item ?. product ?. slug ,
59+ stockAvailabillity : item ?. product ?. inStock ,
60+ } ) ,
61+ ) ;
6462
65- } , [ setWishlist ] )
63+ setWishlist ( productArray ) ;
64+ } ,
65+ [ setWishlist ] ,
66+ ) ;
6667
6768 // getting user by email so I can get his user id
6869 const getUserByEmail = useCallback ( ( ) => {
@@ -75,8 +76,7 @@ const Header = () => {
7576 getWishlistByUserId ( data ?. id ) ;
7677 } ) ;
7778 }
78-
79- } , [ session ?. user ?. email , getWishlistByUserId ] )
79+ } , [ session ?. user ?. email , getWishlistByUserId ] ) ;
8080
8181 useEffect ( ( ) => {
8282 getUserByEmail ( ) ;
0 commit comments