T
TanStack3y ago
fascinating-indigo

rerender for status change

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 } ) }
2 Replies
correct-apricot
correct-apricot3y ago
Is that the actual code or stripped down? Where’s useEffect’s closing ) and dependencies array?
fascinating-indigo
fascinating-indigoOP3y ago
my bad, i forgot to add the dependency properties. it works now.

Did you find this page helpful?