Skip to content

Commit

Permalink
chore: move github api from app.js to header.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
SureshPradhana committed Jul 30, 2024
1 parent 8ec8d35 commit 3cb3f99
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 2 additions & 10 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<Layout stars={countStar}>
<Layout>
<SearchInput search={search} setSearch={setSearch} setType={setType} />
<Error search={search} type={type} />
</Layout>
Expand Down
12 changes: 10 additions & 2 deletions src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
1 change: 0 additions & 1 deletion src/components/Layout/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const Layout = ({ stars, children }) => {
<div className='flex flex-col justify-between min-h-screen'>
<ThemeProvider>
<Header
countStar={stars}
notice={"Under Construction"}
/>
<div className='relative'>
Expand Down

0 comments on commit 3cb3f99

Please sign in to comment.