admin管理员组文章数量:1415476
I want to refetch
the data after save is succeeded.
here is the demo that demonstrates the issue -
=/src/index.js
Issue here is useEffect not gets triggered after data
changes. So the log from line 111
never happens...
Is this behaviour expected?? If not What am I doing wrong??
Also If this behaviour is expected then how to get the latest data programmatically?
I want to refetch
the data after save is succeeded.
here is the demo that demonstrates the issue -
https://codesandbox.io/s/romantic-orla-h9scuc?file=/src/index.js
Issue here is useEffect not gets triggered after data
changes. So the log from line 111
never happens...
Is this behaviour expected?? If not What am I doing wrong??
Also If this behaviour is expected then how to get the latest data programmatically?
Share Improve this question asked Sep 5, 2022 at 13:13 shubhamshubham 4571 gold badge9 silver badges16 bronze badges 6-
I'm not familiar with
react-query
but my guess is thatuseEffect
isn't called becausedata
doesn't actually change. You refetch, but the result didn't change, so nothing needs to change. – Halcyon Commented Sep 5, 2022 at 13:19 - @JatinParmar, Is it expected behaviour? Is it meant to updated in background only?? – shubham Commented Sep 5, 2022 at 13:22
- i have checked and code inside useEffect get executed finely – Jatin Parmar Commented Sep 5, 2022 at 13:48
- inside the codesandbox open the console and click on refetch button you will see console.log will updated – Jatin Parmar Commented Sep 5, 2022 at 13:51
-
After clicking on
refetch
data button?? Are you sure? – shubham Commented Sep 5, 2022 at 13:51
3 Answers
Reset to default 2I don't know much about React-Query but in RTK Query after using refetch
, for this kind of behavior, you should pass isFetching
to useEffect
. This works like a charm and useEffect
runs again when refetching is done.
That happens because you already re-fetch the same data with the same reference because react-query gets it from the cache, So according to useEffect
the data
doesn't change at all, and will not re-execute.
So, That's the expected behavior.
React Query uses structural sharing out of the box.
Please refer below links for more details:
https://tkdodo.eu/blog/react-query-render-optimizations#structural-sharing https://tanstack./query/v4/docs/react/reference/useQuery
本文标签: javascriptreactqueryrefetch don39t trigger useEffectStack Overflow
版权声明:本文标题:javascript - react-query, refetch don't trigger useEffect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745167705a2645782.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论