useDisclosure
A hook for open/close/toggle boolean state.
v0.1.0NativeWindStyleSheetiOSAndroidExpo Go
Installation
npx nativra-cli add use-disclosureWrites use-disclosure.ts to hooks, rewrites imports to your aliases and records hashes in nativra.lock.json. Existing files are never overwritten without asking.
Want to try it first? Open it in the playground: a real React Native project in your browser, with this item installed by the CLI.
Source
Exactly what the CLI writes, before your import aliases are applied.
/** Nativra — useDisclosure. Install: npx nativra-cli add use-disclosure */
import { useCallback, useState } from "react";
export function useDisclosure(initial = false) {
const [isOpen, setOpen] = useState(initial);
const open = useCallback(() => setOpen(true), []);
const close = useCallback(() => setOpen(false), []);
const toggle = useCallback(() => setOpen((v) => !v), []);
return { isOpen, open, close, toggle };
}