Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackall3n/react-hookie
🍪
https://github.com/jackall3n/react-hookie
Last synced: 19 days ago
JSON representation
🍪
- Host: GitHub
- URL: https://github.com/jackall3n/react-hookie
- Owner: jackall3n
- Created: 2019-06-12T09:46:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:33:30.000Z (about 1 year ago)
- Last Synced: 2024-12-11T03:56:40.684Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 780 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Want a hookie? 🍪
#### Cleaning up react hooks
From:
```typescript
const [firstname, setFirstname] = useState('Elon');
const [lastname, setLastname] = useState('Musk');
const [age, setAge] = useState(47);
```To:
```typescript
const initial_state = {
firstname: 'Elon',
lastname: 'Musk',
age: 47
}const { firstname, lastname, age } = useHookie(initial_state, useState);
```Extras:
```typescript
const initial_state = {
firstname: 'Elon',
lastname: 'Musk',
age: {
_: 47,
onSet(value, state) {
console.log(`I am ${value} years old.`)
}
},
bio: '',
onSet({ firstname, lastname, age, bio }) {
bio.set(`Hi, I'm ${firstname} ${lastname} and I'm ${age}.`)
}
}const { firstname, lastname, age, bio } = useHookie(initial_state, useState);
```