Open rostgoat opened 3 years ago
Just as a note: It seems, that the dependencies should be [params, user]
not [params, currentTrip]
, as you are changing the currentTrip inside of that effect.
Now two proposals:
1) extract the effect callback and use it for useDeepCompareEffect
, but also just call it directly as the onClick handler.
2) Or have (for example) an incrementing counter state ("refreshCounter"), that you can increment every time you want that effect to be executed – like in onClick of A – and add that counter to the dependencies: [params, user, refreshCounter]
use-deep-compare-effect
version: 1.6.1node
version: 13.14.0npm
version: 6.14.11Relevant code or config
ParentFile.jsx
What you did:
I am using
react-tabs
to render 2 tabs: A and B.When I initally load the page, by default, Tab A loads and called
useDeepCompareEffect
, which calls my API, gets a deeply nested object and adds to local state.Then I click B, and do some stuff there and at some point I want to go to back to A. However, when I go back to A, I would like to call the API again to get any new changes.
I took a look at the following article about force re-rendering a component but I am not able to do so here (hence the
onClick={forceUpdate}
).How can I force call
useDeepCompareEffect
when I click on A?