diff --git a/src/hooks/useBottomSheetInternal.ts b/src/hooks/useBottomSheetInternal.ts index f0980087d..94c75fd74 100644 --- a/src/hooks/useBottomSheetInternal.ts +++ b/src/hooks/useBottomSheetInternal.ts @@ -1,12 +1,25 @@ import { useContext } from 'react'; -import { BottomSheetInternalContext } from '../contexts/internal'; +import { + BottomSheetInternalContext, + BottomSheetInternalContextType, +} from '../contexts/internal'; -export const useBottomSheetInternal = () => { +export function useBottomSheetInternal( + unsafe?: false +): BottomSheetInternalContextType; + +export function useBottomSheetInternal( + unsafe: true +): BottomSheetInternalContextType | null; + +export function useBottomSheetInternal( + unsafe?: boolean +): BottomSheetInternalContextType | null { const context = useContext(BottomSheetInternalContext); - if (context === null) { + if (unsafe !== true && context === null) { throw "'useBottomSheetInternal' cannot be used out of the BottomSheet!"; } return context; -}; +} diff --git a/src/hooks/useBottomSheetModalInternal.ts b/src/hooks/useBottomSheetModalInternal.ts index 03d88832b..03fd5651d 100644 --- a/src/hooks/useBottomSheetModalInternal.ts +++ b/src/hooks/useBottomSheetModalInternal.ts @@ -1,12 +1,25 @@ import { useContext } from 'react'; -import { BottomSheetModalInternalContext } from '../contexts'; +import { + BottomSheetModalInternalContext, + BottomSheetModalInternalContextType, +} from '../contexts'; -export const useBottomSheetModalInternal = () => { +export function useBottomSheetModalInternal( + unsafe?: false +): BottomSheetModalInternalContextType; + +export function useBottomSheetModalInternal( + unsafe: true +): BottomSheetModalInternalContextType | null; + +export function useBottomSheetModalInternal( + unsafe?: boolean +): BottomSheetModalInternalContextType | null { const context = useContext(BottomSheetModalInternalContext); - if (context === null) { + if (unsafe !== true && context === null) { throw "'BottomSheetModalInternalContext' cannot be null!"; } return context; -}; +}