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; }