I want to make an api call whenever that screen is focused, in mobile application I have an idea that we can use useFocuseffect () but in web how can I implement this please let me know in web how can I make an api call whenever that screen is focused
2
Answers
You can use the
useEffect()
hookOr the
useLayoutEffect()
hook depending on how fast you want your api calls to be made.useEffect()
is triggered after DOM Manipulations are painteduseLayoutEffect()
is triggered synchronously before DOM Manipulations are paintedYou can listen to the
focus
event on thewindow
object for this: