0.2.3 • Published 4 years ago
@ashalfarhan/hooks v0.2.3
Minimal React Hooks
Just a simple React Hooks
📦 Installation
yarn add @ashalfarhan/hooks
#or
npm install @ashalfarhan/hooks --save🔧 Guide
🧲 useToggle
const { open, onToggle, onOpen, onClose, onSwitch } = useToggle();open
booleanCurrent state of toggle
Note: Initially false, to change the initial state pass
trueto theuseToggleparameteronToggle
functionFunction to toggle the state
onClose
functionFunction to set the state to
falseonOpen
functionFunction to set the state to
trueonSwitch
functionFunction to set the state to the param that passed in
🦺 useSafeUpdate
const [count, setCount] = useState(0)
const safeSetCount = useSafeUpdate(setCount)Returns
- safeCallback
functionFunction/callback that is safe when you call if your component accidently unmounted.
🦥 useDebouncedValue
const [searchQuery, setSearchQuery] = useState("")
const debouncedSearchQuery = useDebouncedValue(searchQuery)Returns
- debouncedValue
TValue that lazily update based on delay argument, default to
200(in ms)
👈 usePreviousValue
const prevCount = usePrevious(count)Returns
- previousValue
TThe prevous value of every render, possibly undefined at first