Skip to content

Commit

Permalink
[Fix]관심종목 실시간 삭제 오류 해결
Browse files Browse the repository at this point in the history
delete요청에서 전송이 성공했을 때 받던 json 삭제
Issues #19
  • Loading branch information
김병현 authored and 김병현 committed Sep 20, 2023
1 parent c9da577 commit d7be7ad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/src/components/watchlist/StockItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const StockItem: React.FC<StockItemProps> = ({ company, onDelete }) => {
deleteMutation.mutate(company.companyId, {
onSuccess: () => {
onDelete(company.companyId); // 콜백 함수 호출

}
});
};
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/watchlist/WatchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const WatchList: React.FC<WatchListProps> = ({ currentListType, onChangeListType
const { data: starredData } = useGetStars();

const [starredCompanyIds, setStarredCompanyIds] = useState<number[]>([]);


useEffect(() => {
if (starredData) {

Expand Down
18 changes: 9 additions & 9 deletions client/src/hooks/stars/useDeletestars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { useMutation } from 'react-query';

// DELETE 요청을 수행하는 함수
const deleteStarData = async (companyId: number) => {
const accessToken = localStorage.getItem('accessToken');
const accessToken = localStorage.getItem('accessToken');
const response = await fetch(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080/stars/?companyId=${companyId}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `${accessToken}`
},
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `${accessToken}`
},
});

if (!response.ok) {
throw new Error('Failed to delete star data.');
throw new Error('Failed to delete star data.');
}

return response.json();
// DELETE 요청은 본문을 반환하지 않는 경우가 많으므로 json 변환을 생략
return true; // 삭제가 성공적으로 완료됨을 나타냅니다.
};

// react-query의 useMutation을 사용한 custom hook
const useDeleteStar = () => {
return useMutation(deleteStarData);
};
Expand Down
Empty file added client/src/reducer/starSlice.ts
Empty file.

0 comments on commit d7be7ad

Please sign in to comment.