Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
react-native-use-toggle
import { useState } from "react"
export function useToggle(initialState: boolean = false): [boolean, () => void] {
const [state, setState] = useState<boolean>(initialState)
return [
state,
() => setState(!state)
]
}
export function useBooleanState(initialState: boolean = false): [boolean, () => void, () => void] {
const [state, setState] = useState<boolean>(initialState)
return [
state,
() => setState(true),
() => setState(false)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment