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

Fix: useMemo 오류 해결 #43

Merged
merged 2 commits into from
Nov 30, 2023
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
3 changes: 2 additions & 1 deletion src/pages/Home/Receipt/StatusReceipt/CompleteReceipt.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { message } from "antd";
import axios from "axios";
import React from "react";

Expand All @@ -21,7 +22,7 @@ const CompleteReceipt = ({ orderProps, setStatus, setOrder, fetchData }) => {
.then((res) => {
console.log(res);
if (res.data.success === true) {
alert("픽업완료 처리되었습니다.");
message.info("픽업완료 처리되었습니다.");
// 데이터 다시 fetch
fetchData();
// select된 데이터 변경
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Home/Receipt/StatusReceipt/PendingReceipt.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { message } from "antd";
import axios from "axios";
import React, { useState } from "react";
import { Button, Col, Row } from "react-bootstrap";
Expand Down Expand Up @@ -31,7 +32,7 @@ const PendingReceipt = ({ orderProps, setStatus, setOrder, fetchData }) => {
.then((res) => {
console.log(res);
if (res.status === 200) {
alert("취소되었습니다.");
message.info("취소되었습니다.");
setRefuseModal((prev) => !prev);
// 데이터 다시 fetch
fetchData();
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Home/Receipt/StatusReceipt/ProgressReceipt.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { message } from "antd";
import axios from "axios";
import React from "react";

Expand All @@ -22,7 +23,7 @@ const ProgressReceipt = ({ orderProps, setStatus, setOrder, fetchData }) => {
.then((res) => {
console.log(res);
if (res.data.success === true) {
alert("제조완료 처리되었습니다.");
message.info("제조완료 처리되었습니다.");
// 데이터 다시 fetch
fetchData();
// select된 데이터 변경
Expand Down
34 changes: 5 additions & 29 deletions src/pages/Mypage/MainMypage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";
import { useCookies } from "react-cookie";
import { useNavigate } from "react-router-dom";
import { useSetRecoilState } from "recoil";
Expand All @@ -17,47 +17,23 @@ const MainMypage = React.memo(() => {
const setIsAuthenticated = useSetRecoilState(isAuthenticatedState);
const [cafeInfo, setCafeInfo] = useState({});

// const fetchData = () => {
// const config = {
// withCredentials: true
// };

// axios.get(`${apiUrl}/api/v1/user/info`, config)
// .then((res) => {
// console.log(res);
// setCafeInfo(res.data);
// })
// .catch((err) => console.log(err));
// };

// useEffect(() => {
// fetchData();
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, []);

const fetchData = () => {
const config = {
withCredentials: true
};

return axios.get(`${apiUrl}/api/v1/user/info`, config)
axios.get(`${apiUrl}/api/v1/user/info`, config)
.then((res) => {
console.log(res);
return res.data;
setCafeInfo(res.data);
})
.catch((err) => console.log(err));
};

const memoizedFetchData = useMemo(() => {
useEffect(() => {
fetchData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // empty dependency array means the function doesn't depend on any external variable

useEffect(() => {
memoizedFetchData().then((data) => {
setCafeInfo(data);
});
}, [memoizedFetchData]);
}, []);

const handleLogout = () => {
const config = {
Expand Down