Warning: React has detected a change in the order of Hooks called by MaintenanceTable. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks
해석:
React가 MaintenanceTable 컴포넌트에서 Hook 호출 순서가 바뀌는 것을 감지했습니다. 이 문제를 수정하지 않으면 버그와 오류가 발생할 수 있습니다. 자세한 내용은 Rules of Hooks 문서를 참고하세요.
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
해석:
에러: 잘못된 Hook 호출입니다. Hook은 반드시 함수형 컴포넌트 본문 내부에서만 호출해야 합니다. 아래 중 한 가지 이유로 인해 발생할 수 있습니다:
- React와 렌더러(예: React DOM)의 버전이 일치하지 않을 때
- Hook 규칙을 어길 때
- 앱에 React가 두 번 이상 설치되어 있을 때
export function MaintenanceTable({ isLoading: loading, data }: Props) {
// ...
if (loading) {
return <div>로딩 중...</div>;
}
useEffect(() => {
// ...
}, []);
// ...
}
문제 코드:
if (loading) return <div>로딩 중...</div>;
useEffect(() => {
// ...
}, []);
수정 코드:
useEffect(() => {
// ...
}, []);
if (loading) return <div>로딩 중...</div>;
import { useQuery, useQueryClient } from "@tanstack/react-query"
const queryClient = useQueryClient();
const { data, isLoading } = useQuery({
queryKey: ["equip-maintenance", equipment.id],
queryFn: () => EquipmentEndpoint.listMaintenance(equipment.id),
});
<MaintenanceTable
isLoading={isLoading}
data={data}
reload={() => queryClient.invalidateQueries(["equip-maintenance", equipment.id])}
/>
export function MaintenanceTable({ isLoading, data, reload }) {
// ...
return (
<>
<DataTable ... />
{activeItem && (
<DialogEditMaintenance
activeItem={activeItem}
onSuccess={() => {
setActiveItem(null);
reload?.(); // react-query에서 리스트 리로드 트리거
}}
/>
)}
</>
);
}
export const DialogEditMaintenance = ({ activeItem, onSuccess }) => {
// ...
async function onEditSubmit(data) {
const res = await EquipMaintenanceEndpoint.update(activeItem.id, data);
if (res.ok) {
onSuccess?.();
}
}
// ...
};
React Provider란 무엇인가? (0) | 2025.07.01 |
---|---|
React - useQueryClient(). invalidateQueries (0) | 2025.06.08 |
React - useQuery (0) | 2025.06.08 |
React - useContext를 사용하기 전과 후의 구조 비교 (0) | 2025.06.08 |
React - useCallback을 활용한 함수 최적화 전략 (0) | 2025.06.07 |