Skip to content

Commit

Permalink
fetch-api
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadpy8 committed Aug 26, 2023
1 parent 42de00b commit 7125dd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
28 changes: 15 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -11,21 +13,21 @@ function App() {
const router = useRoutes(routes);

return (
// <ContextDataProvider>
<div className="app">
{/* Start Content */}
<Headers />
{router}
<CartContextProvider>
<div className="app">
{/* Start Content */}
<Headers />
{router}

{/* Finish Content */}
{/* Finish Content */}

<footer>
<a target={"_blank"}>
mohammad
</a>
</footer>
</div>
// </ContextDataProvider>
<footer>
<a target={"_blank"}>
mohammad
</a>
</footer>
</div>
// </CartContextProvider>
);
}

Expand Down
14 changes: 13 additions & 1 deletion src/context/CartContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useState } from 'react';
import React, { createContext, useEffect, useState } from 'react';

import { Produts } from '../types/products.types';

Expand All @@ -20,6 +20,18 @@ const CartContextProvider = ({ children }: CartProps) => {

const [userCart, setUserCart] = useState<Produts[]>([]);
const [shop, setShop] = useState<Produts[]>([]);

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) => {

Expand Down

0 comments on commit 7125dd5

Please sign in to comment.