Error combining useQuery with useState #4359
Replies: 3 comments
-
function Component () {
...
if (isSuccess) {
setData(personajes);
}
} If this is inside of component function, this will run in every render after Flow
|
Beta Was this translation helpful? Give feedback.
-
Indeed, but my question is: what is the solution to save the response of useQuery as a state of type useState? |
Beta Was this translation helpful? Give feedback.
-
well you'd need a useEffect for that:
but honestly, I would advise against copying the state of react-query anywhere else. This is a discussion at best, not an issue, so moving. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
When we make a fetch request to an api we can save the resulting data as status to later filter based on certain options through useState:
However if we apply the same concept with react query, it does not give an error because it exceeds the number of renderings:
Your minimal, reproducible example
https://github.com/Juanjo-GEx
Steps to reproduce
Apply the mentioned code.
Expected behavior
The expected result would be the same as in the first example, but this is not the case and it gives an error.
How often does this bug happen?
Every time
Screenshots or Videos
ERROR:
Uncaught Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.
Platform
Chrome
react-query version
4.12.0
TypeScript version
No response
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions