Skip to content

Commit

Permalink
[Fix] 주식주문 관련 회원정보 fetching 오류 수정
Browse files Browse the repository at this point in the history
- 로그인 비활성화 살태일 때는 보유 현금 등 회원관련된 정보를 fetching 하지 않고, 로그인 활성화 시 fetcing 하도록 로직 구현

Issues #17
  • Loading branch information
novice1993 committed Sep 13, 2023
1 parent ceb96e6 commit d9fbc3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
12 changes: 10 additions & 2 deletions client/src/hooks/useGetCash.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from "react";
import { useQuery } from "react-query";
import { useSelector } from "react-redux";
import axios from "axios";
Expand All @@ -8,8 +9,15 @@ const url = "http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080

const useGetCash = () => {
const isLogin = useSelector((state: StateProps) => state.login);
const { data, isLoading, isError } = useQuery("cash", getCashData, {
enabled: isLogin === 1,

useEffect(() => {
if (isLogin === 1) {
refetch();
}
}, [isLogin]);

const { data, isLoading, isError, refetch } = useQuery("cash", getCashData, {
enabled: false,
});

return { cashData: data, cashLoading: isLoading, cashError: isError };
Expand Down
12 changes: 10 additions & 2 deletions client/src/hooks/useGetHoldingStock.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from "react";
import { useQuery } from "react-query";
import { useSelector } from "react-redux";
import axios from "axios";
Expand All @@ -7,8 +8,15 @@ const url = "http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080

const useGetHoldingStock = () => {
const isLogin = useSelector((state: StateProps) => state.login);
const { data, isLoading, isError } = useQuery("holdingStock", getHoldingStock, {
enabled: isLogin === 1,

useEffect(() => {
if (isLogin === 1) {
refetch();
}
}, [isLogin]);

const { data, isLoading, isError, refetch } = useQuery("holdingStock", getHoldingStock, {
enabled: false,
});
return { holdingStockData: data, holdingStockLoading: isLoading, holdingStockError: isError };
};
Expand Down
1 change: 0 additions & 1 deletion client/src/hooks/useGetStockChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const useGetStockChart = (companyId: number) => {
useEffect(() => {
if (stockPrice) {
setChartData(stockPrice);

const { interval, min } = calculateYAxisOptions(stockPrice);
setYAxisInterval(interval);
setYAxisMinPrice(min);
Expand Down
11 changes: 9 additions & 2 deletions client/src/hooks/useGetStockOrderRecord.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from "react";
import { useQuery } from "react-query";
import { useSelector } from "react-redux";
import axios from "axios";
Expand All @@ -7,8 +8,14 @@ const url = "http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080

const useGetStockOrderRecord = () => {
const isLogin = useSelector((state: StateProps) => state.login);
const { data, isLoading, isError } = useQuery("orderRecord", getOrderRecord, {
enabled: isLogin === 1,

useEffect(() => {
if (isLogin === 1) {
refetch();
}
}, [isLogin]);
const { data, isLoading, isError, refetch } = useQuery("orderRecord", getOrderRecord, {
enabled: false,
});

return { orderRecordData: data, orderRecordLoading: isLoading, orderRecordError: isError };
Expand Down

0 comments on commit d9fbc3e

Please sign in to comment.