-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow unsafe usage for useBottomSheetInternal & useBottomSheetM…
…odalInternal (#740)(by @jembach) * feat: add useBottomSheetInternal_unsafe & useBottomSheetModalInternal_unsafe to access context * chore: export hooks useBottomSheetInternal_unsafe and useBottomSheetModalInternal_unsafe * refactor: combined unsafe hooks with default hooks using an argument * chore(useBottomSheetInternal): use function overloading instead of interface * chore(useBottomSheetModalInternal): use function overloading instead of interface * chore: fixed spacing Co-authored-by: gorhom <[email protected]>
- Loading branch information
Showing
2 changed files
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |