Rule of hooks error

Hello, I'm discovering T3 Stack and I'm struggling with the react rule of hooks. I would like to call this query :
const onPlaylistClick = () => {
const { data: songsList } = api.spotify.songsList.useQuery(
"3rsOyZnnXMBOiyBVVvpacn",
);
console.log(songsList);
};
const onPlaylistClick = () => {
const { data: songsList } = api.spotify.songsList.useQuery(
"3rsOyZnnXMBOiyBVVvpacn",
);
console.log(songsList);
};
When I click on my button Is there any way to call the query like a mutation ? Thanks in advance !
7 Replies
nexxel
nexxel•2y ago
you can't call a hook conditionally that breaks the rules of react
How What
How WhatOP•2y ago
Yeah I see that but then how can I do it ? 😅
nexxel
nexxel•2y ago
easiest solution is to just make the query a mutation or use the enabled property in react query
How What
How WhatOP•2y ago
Oh okay thanks
nexxel
nexxel•2y ago
Dependent Queries | TanStack Query Docs
Dependent (or serial) queries depend on previous ones to finish before they can execute. To achieve this, it's as easy as using the enabled option to tell a query when it is ready to run:
nexxel
nexxel•2y ago
syntax will be a bit different but you get the idea
How What
How WhatOP•2y ago
thanks i'll try this
Want results from more Discord servers?
Add your server