Skip to content

Commit 828dc8f

Browse files
authored
Merge pull request #843 from karrioapi/fix/infinite-rerender-useconnections-hook
2 parents bd09988 + 42bd001 commit 828dc8f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/hooks/carrier-connections.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export function useConnections() {
1515
system_connections,
1616
} = useSystemConnections();
1717

18+
const memoizedUserConnections = React.useMemo(() => user_connections, [JSON.stringify(user_connections)]);
19+
const memoizedSystemConnections = React.useMemo(() => system_connections, [JSON.stringify(system_connections)]);
20+
1821
React.useEffect(() => {
1922
if (!isUserFetched || !isSystemFetched) {
2023
return;
2124
}
2225

23-
const newCarrierOptions = [...user_connections, ...system_connections]
26+
const newCarrierOptions = [...memoizedUserConnections, ...memoizedSystemConnections]
2427
.filter((_) => _.active && (_.config?.shipping_options || []).length > 0)
2528
.reduce(
2629
(acc, _) => ({
@@ -36,7 +39,7 @@ export function useConnections() {
3639
);
3740

3841
setCarrierOptions(newCarrierOptions);
39-
}, [isUserFetched, isSystemFetched, user_connections, system_connections]);
42+
}, [isUserFetched, isSystemFetched, memoizedUserConnections, memoizedSystemConnections]);
4043

4144
return {
4245
carrierOptions,

0 commit comments

Comments
 (0)