【发布时间】:2021-12-28 23:50:04
【问题描述】:
我正在运行 useFocusEffect 进行 API 调用(使用 reactQuery),但出现此错误:
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
这是引发错误的具体代码,我不知道错误是来自 reactQuery useMutation 还是来自 react 导航的 useFocusEffect:
export const OrderStatementLoading = () => {
const {
mutateAsync: createSchedulePayment,
isLoading: isLoadingSave,
isSuccess: isSuccessSave,
reset,
} = useMutation(//...useMutationParams);
useFocusEffect(
useCallback(() => {
createSchedulePayment()
.then(() => console.log('success'))
.catch(() => console.log('error'))
.finally(() => {
reset();
});
}, [reset, createSchedulePayment]),
);
return {// redered content}
};```
【问题讨论】:
标签: reactjs react-native react-navigation react-query