diff --git a/src/App.tsx b/src/App.tsx index 7f63f04..814e678 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,6 +2,8 @@ import React from "react"; import { AiFillStar, AiOutlineStar, AiOutlineShoppingCart } from "react-icons/ai"; import Headers from "./components/Headers"; +import CartContextProvider from "./context/CartContextProvider"; + import Home from "./Pages/home/Home"; import "./App.css"; import { useRoutes } from "react-router-dom"; @@ -11,21 +13,21 @@ function App() { const router = useRoutes(routes); return ( - // -
- {/* Start Content */} - - {router} + +
+ {/* Start Content */} + + {router} - {/* Finish Content */} + {/* Finish Content */} - -
- // + +
+ // ); } diff --git a/src/context/CartContextProvider.tsx b/src/context/CartContextProvider.tsx index da1ae12..512d04d 100644 --- a/src/context/CartContextProvider.tsx +++ b/src/context/CartContextProvider.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useState } from 'react'; +import React, { createContext, useEffect, useState } from 'react'; import { Produts } from '../types/products.types'; @@ -20,6 +20,18 @@ const CartContextProvider = ({ children }: CartProps) => { const [userCart, setUserCart] = useState([]); const [shop, setShop] = useState([]); + + useEffect(() => { + + fetch("https://fakestoreapi.com/products") + .then(res => res.json()) + .then(data => { + console.log("data =>", data); + setShop(data); + }) + .catch(err => console.log(err)); + + }, []) const addProduts = (id: number) => {