Hey, some React tutorials mention `useFocusEffect`...
# javascript
h
Hey, some React tutorials mention
useFocusEffect
but I can't find it in the wrappers. Does anyone know if it's in and how to use it?
a
@turansky ^^?
h
I searched a little myself and it looks like it's part of
react-navigation/native
which in turn relies on
react-native
. So it won't be part of the wrappers, but maybe there is something similar? I tried to ask perplexity, but that only referred me to non working examples with
useFocusEffect
and
NavigationEvents
(also part of
react-navigation
). Alternatively, I just want to do something after the
FC
is navigated back to (navigate(-1)). Because it seems that the data loader are not executed again if the user returns to a
FC
t
Do you use
react-router
?
h
Yes, I do.
t
It's second time when you ask "How I can receive TanStack Query functionality in React Router?". Probably it's time to take a look at TanStack Query. Refetch on focus - default mode of
useQuery
hook.
h
I wasn't aware it's so versatile. My colleague and I really need to look at the complete TanStack Query functionality then. Thank you for pointing it out. Having a quick look, am I seeing it right that we would essentially completely ditch data loaders in favour of tanstack query?
t
In common case TanStack Query can do all required job. Some integration with React Router loaders can be helpful in advanced scenarious when you want really smooth transitions between pages (without white screen).
h
Okay, thank you very much.
t
cc @Michael Porotkin