Skip to content

Commit

Permalink
fix callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar committed Jan 2, 2024
1 parent 8321a79 commit 10aa387
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/components/detail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useEffect, useState } from "react";
import { LineChart, Line, XAxis, YAxis, Tooltip, Legend } from "recharts";
import github, { getRepoLangAPI } from "../utils/axios";
import Progress from "./progress";

function Detail(repoFocused) {
const [detail, setdetail] = useState(null);

Expand Down
28 changes: 13 additions & 15 deletions src/components/languages.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import React, { useEffect, useState } from "react";
import { LineChart, Line, XAxis, YAxis, Tooltip, Legend } from "recharts";
import github, { getRepoLangAPI } from "../utils/axios";
import React, { useEffect, useState, useCallback } from "react";
import { getRepoLangAPI } from "../utils/axios";
import Progress from "./progress";
function Languages(focus, user_name) {

function Languages({ focus, user_name }) {
const [data, setData] = useState(null);

const getLangData = async () => {
await getRepoLangAPI(focus, user_name)
.then(({ data: response }) => {
console.log("log ~ .then ~ response:", response);
setData(response);
})
.catch((error) => {
throw new Error(("errors.fetch-error-user-data", { data: error.data }));
});
};
const getLangData = useCallback(async () => {
try {
const { data: response } = await getRepoLangAPI(focus, user_name);
setData(response);
} catch (error) {
console.error("Error fetching language data:", error);
}
}, [focus, user_name]);

useEffect(() => {
getLangData();
}, [focus, user_name]);
}, [getLangData]);

return (
<>
Expand Down

0 comments on commit 10aa387

Please sign in to comment.