Skip to content

Commit

Permalink
fix: too many re-renders
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jul 18, 2022
1 parent 810fccb commit c68c558
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/widget/src/hooks/useSwapRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ export const useSwapRoutes = () => {
(route) => route.id === currentRoute?.id,
);
const recommendedRoute = data?.routes[0];
// we don't want to set the current route again if it's already selected from existing routes
if (!isCurrentRouteInSet && currentRoute !== recommendedRoute) {
// we don't want to set the current route again on mount if it's already selected from existing routes
if (!isCurrentRouteInSet) {
setCurrentRoute(recommendedRoute);
}
}, [currentRoute, data?.routes, setCurrentRoute]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data?.routes, setCurrentRoute]);

return {
routes: data?.routes,
Expand Down

0 comments on commit c68c558

Please sign in to comment.