From 7b8515011893f8aa03d64a75e74b1da1e317f7d0 Mon Sep 17 00:00:00 2001 From: Richard Lindhout Date: Wed, 2 Aug 2023 21:03:02 +0200 Subject: [PATCH] fix: improve make onChangeIndex not required --- README.md | 4 ++-- src/TabsProvider.tsx | 16 +++++++--------- src/utils.tsx | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7ab6db4..03ccbb8 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,10 @@ function Example() { return ( { +}: TabsProviderProps) { const [index, setIndex] = useState(defaultIndex || 0); const goTo = React.useCallback( (ind: number) => { setIndex(ind); - onChangeIndex(ind); + onChangeIndex?.(ind); }, [setIndex, onChangeIndex] ); - return ( - - {children} - - ); -}; + const value = React.useMemo(() => ({ goTo, index }), [goTo, index]); + + return {children}; +} diff --git a/src/utils.tsx b/src/utils.tsx index c890068..c87da62 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -71,6 +71,6 @@ export type IndicatorReturns = [RefObject | undefined, () => any, Animated export interface TabsProviderProps { children: any; - onChangeIndex: (index: number) => void; + onChangeIndex?: (index: number) => void; defaultIndex?: number; }