Skip to content

Commit e51e523

Browse files
committed
fix: memoized the scrollable creator hook
1 parent 2a562bb commit e51e523

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/hooks/useBottomSheetScrollableCreator.tsx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { ReactElement } from 'react';
1+
import { type ReactElement, useCallback } from 'react';
22
import {
3-
BottomSheetScrollView,
43
type BottomSheetScrollableProps,
4+
BottomSheetScrollView,
55
} from '../components/bottomSheetScrollable';
66

77
type BottomSheetScrollableCreatorConfigs = {} & BottomSheetScrollableProps;
@@ -34,16 +34,27 @@ export function useBottomSheetScrollableCreator<T = any>({
3434
focusHook,
3535
scrollEventsHandlersHook,
3636
enableFooterMarginAdjustment,
37-
}: BottomSheetScrollableCreatorConfigs = {}): (props: T) => ReactElement<T> {
38-
// @ts-ignore
39-
return ({ data: _, ...props }: T, ref: never) => (
40-
// @ts-ignore
41-
<BottomSheetScrollView
42-
ref={ref}
43-
{...props}
44-
focusHook={focusHook}
45-
scrollEventsHandlersHook={scrollEventsHandlersHook}
46-
enableFooterMarginAdjustment={enableFooterMarginAdjustment}
47-
/>
37+
}: BottomSheetScrollableCreatorConfigs = {}): (
38+
props: T,
39+
ref?: never
40+
) => ReactElement<T> {
41+
return useCallback(
42+
function useBottomSheetScrollableCreator(
43+
// @ts-expect-error
44+
{ data: _, ...props }: T,
45+
ref?: never
46+
): ReactElement<T> {
47+
return (
48+
// @ts-expect-error
49+
<BottomSheetScrollView
50+
ref={ref}
51+
{...props}
52+
focusHook={focusHook}
53+
scrollEventsHandlersHook={scrollEventsHandlersHook}
54+
enableFooterMarginAdjustment={enableFooterMarginAdjustment}
55+
/>
56+
);
57+
},
58+
[focusHook, scrollEventsHandlersHook, enableFooterMarginAdjustment]
4859
);
4960
}

0 commit comments

Comments
 (0)