Skip to content

Commit 37ecd7b

Browse files
chore: move github api from app.js to header.jsx (#229)
1 parent 8ec8d35 commit 37ecd7b

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/App.jsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ import Layout from "./components/Layout/Layout";
77
function App() {
88
const [search, setSearch] = useState("");
99
const [type, setType] = useState("");
10-
const [countStar, setCountStar] = useState(0);
11-
12-
useEffect(() => {
13-
fetch("https://api.github.com/repos/devvsakib/github-error-solve")
14-
.then((response) => response.json())
15-
.then((data) => setCountStar(data.stargazers_count))
16-
.catch((error) => console.error("Error fetching GitHub stars:", error));
17-
}, []);
18-
console.log(countStar)
10+
1911
return (
2012
<>
21-
<Layout stars={countStar}>
13+
<Layout>
2214
<SearchInput search={search} setSearch={setSearch} setType={setType} />
2315
<Error search={search} type={type} />
2416
</Layout>

src/components/Header/Header.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ import { Link } from "react-router-dom";
1010

1111
import { HiMoon, HiSun } from "react-icons/hi";
1212
import { ThemeContext } from "../../context/ThemeContext";
13-
import { useContext, useState } from "react";
13+
import { useContext, useState, useEffect} from "react";
1414

15-
function Header({ countStar, notice }) {
15+
function Header({notice }) {
1616
const { theme, toggleTheme } = useContext(ThemeContext);
1717
const [open, setOpen] = useState(false);
18+
const [countStar, setCountStar] = useState(0);
19+
20+
useEffect(() => {
21+
fetch("https://api.github.com/repos/devvsakib/github-error-solve")
22+
.then((response) => response.json())
23+
.then((data) => setCountStar(data.stargazers_count))
24+
.catch((error) => console.error("Error fetching GitHub stars:", error));
25+
}, []);
1826

1927
const navLink = [
2028
{

src/components/Layout/Layout.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const Layout = ({ stars, children }) => {
1313
<div className='flex flex-col justify-between min-h-screen'>
1414
<ThemeProvider>
1515
<Header
16-
countStar={stars}
1716
notice={"Under Construction"}
1817
/>
1918
<div className='relative'>

0 commit comments

Comments
 (0)