Skip to content

Commit

Permalink
chore: update useBoolean
Browse files Browse the repository at this point in the history
  • Loading branch information
ambar committed Jan 26, 2022
1 parent 07534b9 commit 55e13bf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/griffith/src/hooks/useBoolean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useCallback, useState} from 'react'
import {useCallback, useState, useRef} from 'react'

/**
* Create a boolean value and switches for changing it
Expand All @@ -13,11 +13,11 @@ import {useCallback, useState} from 'react'
*/
const useBoolean = (initialState: boolean | (() => boolean) = false) => {
const [value, setValue] = useState(initialState)
const valueSwitch = {
const valueSwitch = useRef({
on: useCallback(() => setValue(true), []),
off: useCallback(() => setValue(false), []),
toggle: useCallback(() => setValue((v) => !v), []),
} as const
}).current
return [value, valueSwitch] as const
}

Expand Down

0 comments on commit 55e13bf

Please sign in to comment.