mshumayl / ai-daleel

AI Daleel source code.
https://ai-daleel.vercel.app
1 stars 0 forks source link

Prevent data re-fetch on component re-render #20

Closed mshumayl closed 1 year ago

mshumayl commented 1 year ago

https://stackoverflow.com/questions/58712833/react-how-to-prevent-re-fetching-data-when-component-re-renders

mshumayl commented 1 year ago

This can be done by moving all data fetches into a useEffect with an empty dependency array.

mshumayl commented 1 year ago

There may be nothing wrong with the useEffects after all. This is actually due to a react-query behaviour (via tRPC):

https://stackoverflow.com/questions/70337333/react-query-refetch-on-window-focus-but-not-otherwise