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();
});
更多回答
我是一名优秀的程序员,十分优秀!