devTej – 15-10 Oct 8

I read react 18 documentation, that component will render twice for future features. This feature will give React better performance out-of-the-box, but requires components to be resilient to effects being mounted and destroyed multiple times as per them when the user switches the tab and comes back it will persist the previous state, My question is even if it persists the state, it will still run the useEffect which may make API calls and what is the use of unmounting and remounting the component in current release
Rhys557d ago
From my understanding, the main reason for it running twice is people were putting things in use state that shouldn’t be in use state, I.e api calls so it was changed to discourage that Take a look at react query: The basic concept is instead of using useEffect for API calls, you should write your API call as a hook as it gives you better control of the data flow @devTej
TanStack Query | React Query, Solid Query, Svelte Query, Vue Query
Powerful asynchronous state management, server-state utilities and data fetching for TS/JS, React, Solid, Svelte and Vue
Unknown User556d ago