An easy hooks library
npm install friendly-hooksjavascript
const [inputValue, setInputValue] = useState("")
useDebounce(getData, 1000, [inputValue])
`
In this example getData will be call only after 1s from the last char typed. The dependencies are used for reset the delay while the user is typing.
$3
Have you ever want a useEffect that runs only when you update some data? that is the case where it comes to handy useUpdateEffect and useStrictUpdateEffect. Why 2 hooks that do the same thing? because in React 18 the strick mode cause 2 renders, so if you are in React 18 and using strick mode you need to use useStrictUpdateEffect else useUpdateEffect
example
`javascript
useUpdateEffect(()=>{
// your code
},[dependencies])
`
The same is for useStrictUpdateEffect, it's like componentWillUpdate in class components. The first time it's call it returns null, then it will return the callback like a normal useEffect.
$3
An easy hooks that let you save and use the previous value of something
`javascript
const [state, setState] = useState(initState)
const prevState = usePrevious(state);
`
And that's it!!
$3
A simple hook for switch boolean value
`javascript
const [isVisible, setIsVisible] = useToggle(defaultValue)
return (
{
isVisible && //some jsx
}
)
``