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
3 Replies
Rhys
Rhys3y 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: https://tanstack.com/query/v4 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 User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/902647189120118794/1028323395676409887

Did you find this page helpful?