Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/useBoolean/useBoolean.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface UseBooleanDocsProps {
* returns the value, an object containing function for toggle, setTrue and setFalse.
*
* __Use `toggle` with caution__, attaching to buttons can cause unintended consequences from double clicks.
* Also, re-exposes the `setValue` function in case required.
*
*/
export const UseBooleanDocs: React.FC<UseBooleanDocsProps> = (
_props: UseBooleanDocsProps
Expand Down
2 changes: 2 additions & 0 deletions src/useBoolean/useBoolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function useBoolean(startState = false): [
toggle: () => void
setTrue: () => void
setFalse: () => void
setValue: React.Dispatch<React.SetStateAction<boolean>>
}
] {
const [value, setValue] = useState(startState)
Expand All @@ -23,6 +24,7 @@ export function useBoolean(startState = false): [
toggle: (): void => setValue((state) => !state),
setTrue: (): void => setValue(true),
setFalse: (): void => setValue(false),
setValue,
}),
[setValue]
)
Expand Down
1 change: 1 addition & 0 deletions src/useModal/useModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface UseModalDocsProps {
* Utility hook for modal state
*
* returns the visibility of the modal and functions to `show` and `hide`.
* Also, re-exposes the `set` function in case required.
*
*/
export const UseModalDocs: React.FC<UseModalDocsProps> = (
Expand Down
12 changes: 9 additions & 3 deletions src/useModal/useModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { useBoolean } from '../useBoolean'
*/
export function useModal(
startState = false
): [visible: boolean, show: () => void, hide: () => void] {
const [visible, { setTrue: show, setFalse: hide }] = useBoolean(startState)
return [visible, show, hide]
): [
visible: boolean,
show: () => void,
hide: () => void,
set: React.Dispatch<React.SetStateAction<boolean>>
] {
const [visible, { setTrue: show, setFalse: hide, setValue: set }] =
useBoolean(startState)
return [visible, show, hide, set]
}