gpt4 book ai didi

diffrence between isSuccess and onSuccess in react-query [closed](反应查询[已关闭]中isSuccess和onSuccess之间的差异)

转载 作者:bug小助手 更新时间:2023-10-25 10:40:55 26 4
gpt4 key购买 nike




I want to do some logic when useMutaion is success, and I don't know what and when should I use, 'isSuccess' the boolean or 'onSuccess' the callback function?

当useMutaion是Success时,我想做一些逻辑操作,我不知道应该使用什么,什么时候应该使用,‘Success’是布尔值,还是‘onSuccess’是回调函数?


 const {
mutate: createRoom,
isLoading,
isError,
isSuccess,
} = useCreateRooom();

更多回答
优秀答案推荐


diffrence between isSuccess and onSuccess



Depends what exactly you want to do when the request has succeeded. If you want display some JSX permanently (until the flag changes), isSuccess flag may be useful.

取决于请求成功后您到底想要执行什么操作。如果您希望永久显示某些JSX(直到标志更改),isSuccess标志可能会很有用。


{isSuccess && <div>Request success</div>}

However if you want to do something once when succeeded, e.g. show a tooltip or call some cleanup function - onSuccess may be better option.

但是,如果您想在成功后执行一次操作,例如显示工具提示或调用某个清理函数-onSuccess可能是更好的选择。


onSuccess(() => {
showTooltip('Success!', 5000);
clearState();
});

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com