1 answer

★ Best answer

The double request in development is almost certainly due to React 18 with StrictMode enabled, which mounts and unmounts components on purpose to detect side effects. To avoid it, make sure your useEffect has an empty dependency array `[]` if you only want it to run once on mount, and clean up pending requests with an AbortController or a boolean flag in the cleanup function so it doesn't try to update state if the component unmounts. If you already have that and it's still slow, the problem is probably that you're refreshing state unnecessarily or causing massive re-renders; use React DevTools Profiler to see where it's getting stuck, and consider using `useMemo` or `useCallback` if you have a lot of calculations or pass callbacks to child components.

Your answer

Log into answer.