Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikeibberson/useful-state

Common hooks for managing simple states in React
https://github.com/mikeibberson/useful-state

hooks react react-hooks

Last synced: 19 days ago
JSON representation

Common hooks for managing simple states in React

Awesome Lists containing this project

README

        

⚙️ useful-state



Status
Coverage Status


Custom state hooks for simple UI goals.

useOpen


Use this to attach a ref to the open/close state of your UI component.

| Methods | Description |
| ------- | ---------------------------------------- |
| `open` | Assign truthy value to `isOpen` property |
| `close` | Assign falsy value to `isOpen` property |

useToggle


Super similar to the hook above, only it ships with a toggle method and no refs.

| Methods | Description |
| -------- | ---------------------------- |
| `open` | Assign truthy value to state |
| `close` | Assign falsy value to state |
| `toggle` | Inverts current state value |

useValue


Most often used with inputs; provides an easy way to track value changes and manage focus.

| Methods | Description |
| ---------- | ---------------------------------------------------------- |
| `onFocus` | Call the .focus() method on ref if it exists |
| `onClear` | Clear state |
| `onChange` | Assign target value to state (provide an `event` argument) |