Skip to content

Commit 6d79b19

Browse files
dyst5422cansuaa
andauthored
fix: Memoize actions (#102)
Co-authored-by: Cansu Aksu <45541797+cansuaa@users.noreply.github.com>
1 parent 60a26d1 commit 6d79b19

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/use-collection-state.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { useReducer } from 'react';
3+
import { useReducer, useMemo } from 'react';
44
import { createActions, collectionReducer, CollectionReducer } from './utils.js';
55
import { UseCollectionOptions, CollectionState, CollectionRef, CollectionActions } from './interfaces';
66

@@ -16,11 +16,8 @@ export function useCollectionState<T>(
1616
filteringText: options.filtering?.defaultFilteringText ?? '',
1717
propertyFilteringQuery: options.propertyFiltering?.defaultQuery ?? { tokens: [], operation: 'and' },
1818
});
19-
return [
20-
state,
21-
createActions({
22-
dispatch,
23-
collectionRef,
24-
}),
25-
] as const;
19+
20+
const actions = useMemo(() => createActions({ dispatch, collectionRef }), [dispatch, collectionRef]);
21+
22+
return [state, actions] as const;
2623
}

0 commit comments

Comments
 (0)