Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mikeibberson/useful-state
- Owner: MikeIbberson
- License: mit
- Created: 2019-12-10T00:06:20.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T04:26:50.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T12:15:57.286Z (about 1 month ago)
- Topics: hooks, react, react-hooks
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/useful-state
- Size: 1.29 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
⚙️ useful-state
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) |