pollingInterval broken #3224
-
Hi, I'm trying to get some basic polling working: const { data, isSuccess } = usePollingQuery('test', { pollingInterval: 3000 });
useEffect(() => {
console.log('data', data); // I'm assuming it will output with each response
}, [data]); The network requests are being sent every three seconds and are successful. My API is returning the same data each time but nothing in the console except for the first time the query is run. Any tips on how to fix this? I want to output the It seems like if we add a response transformer and add a timestamp to the response, it will trigger the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@mauriceoc : this sounds like expected behavior to me. By default, making an API call via In other words: const jsonString = '{"a": 1}';
const obj1 = JSON.parse(jsonString);
const obj2 = JSON.parse(jsonString);
console.log(obj1 === obj2) // FALSE, they are two different objects in memory However, if you have a query that keeps fetching the "same" data, this would create a problem. If we always replaced the existing data entirely, then your component would always re-render every time the polling request came back due to the new references, even though the data was conceptually the same. So, RTKQ tries to intelligently merge the fetched data into the existing data, and reuses the existing references as much as possible if the contents appear to be the same. That way, your component will only re-render if the contents have meaningfully changed. Beyond that, I'm not sure what you're trying to accomplish by having a |
Beta Was this translation helpful? Give feedback.
@mauriceoc : this sounds like expected behavior to me.
By default, making an API call via
fetch
or XHR and then parsing the JSON response will result in new object references being created, even if the contents of the response is conceptually the same.In other words:
However, if you have a query that keeps fetching the "same" data, this would create a problem. If we always replaced the existing data entirely, then your component would always re-render every time the polling request came back due to the new r…