From 3cb3f99799cf149be4ee58655e52c3cbaadf6714 Mon Sep 17 00:00:00 2001 From: SureshPradhana Date: Tue, 30 Jul 2024 18:57:25 +0530 Subject: [PATCH] chore: move github api from app.js to header.jsx --- src/App.jsx | 12 ++---------- src/components/Header/Header.jsx | 12 ++++++++++-- src/components/Layout/Layout.jsx | 1 - 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 3ceafc0..9f44d44 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -7,18 +7,10 @@ import Layout from "./components/Layout/Layout"; function App() { const [search, setSearch] = useState(""); const [type, setType] = useState(""); - const [countStar, setCountStar] = useState(0); - - useEffect(() => { - fetch("https://api.github.com/repos/devvsakib/github-error-solve") - .then((response) => response.json()) - .then((data) => setCountStar(data.stargazers_count)) - .catch((error) => console.error("Error fetching GitHub stars:", error)); - }, []); -console.log(countStar) + return ( <> - + diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx index cedd611..e069bb3 100644 --- a/src/components/Header/Header.jsx +++ b/src/components/Header/Header.jsx @@ -10,11 +10,19 @@ import { Link } from "react-router-dom"; import { HiMoon, HiSun } from "react-icons/hi"; import { ThemeContext } from "../../context/ThemeContext"; -import { useContext, useState } from "react"; +import { useContext, useState, useEffect} from "react"; -function Header({ countStar, notice }) { +function Header({notice }) { const { theme, toggleTheme } = useContext(ThemeContext); const [open, setOpen] = useState(false); + const [countStar, setCountStar] = useState(0); + + useEffect(() => { + fetch("https://api.github.com/repos/devvsakib/github-error-solve") + .then((response) => response.json()) + .then((data) => setCountStar(data.stargazers_count)) + .catch((error) => console.error("Error fetching GitHub stars:", error)); + }, []); const navLink = [ { diff --git a/src/components/Layout/Layout.jsx b/src/components/Layout/Layout.jsx index d6480ac..5b817ee 100644 --- a/src/components/Layout/Layout.jsx +++ b/src/components/Layout/Layout.jsx @@ -13,7 +13,6 @@ const Layout = ({ stars, children }) => {