Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add useBottomSheetInternal_unsafe & useBottomSheetModalInternal… #740

21 changes: 17 additions & 4 deletions src/hooks/useBottomSheetInternal.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}
21 changes: 17 additions & 4 deletions src/hooks/useBottomSheetModalInternal.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}