Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move github api from app.jsx to header.jsx #229

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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