@welingtonms/use-value
v1.0.3
Published
A custom React hook to set/get state using a single function.
Downloads
3
Maintainers
Readme
use-value
A custom React hook that wraps the existing useState to be used similarly to jQuery's .val().
Usage
import { useValue } from '@welingtonms/use-value';
function CollapseSample() {
const collapsed = useValue(false);
return (
<div>
{collapsed() ? 'ON' : 'OFF'}
<button
type="button"
onClick={() => {
collapsed(!collapsed());
}}
>
Toggle like this
</button>
<button
type="button"
onClick={() => {
collapsed((isCollapsed) => !isCollapsed);
}}
>
Or like this
</button>
</div>
);
}