rerender doesn't happen when status changes #4996
Answered
by
louis-young
weidezhang
asked this question in
Q&A
-
Hi, I'm wondering when the useQuery status change, why it doesn't trigger rerender ? I used the isSuccess property returned from useQuery but I don't see the useEffect gets called when data is successfully fetched. Any help is appreciated !
const component = () => {
const { data, isLoading, isSuccess } = useQuery(
['image'],
async () => {
//fetch some image
},
onSuccess: ()=> {
//some logic for success callback, this gets called with no problem.
}
);
React.useEffect(() => {
if( isSuccess) { console.log("success") }
}
return (
if(isSuccess) {
//render jsx for success case
} else
{
//render jsx for default cases
}
)
}
|
Beta Was this translation helpful? Give feedback.
Answered by
louis-young
Feb 23, 2023
Replies: 1 comment
-
Hi 👋 The query status changing does trigger a re-render. The issue is that your effect has no dependency list, meaning it'll only run once. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
louis-young
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi 👋
The query status changing does trigger a re-render. The issue is that your effect has no dependency list, meaning it'll only run once.