https://github.com/jackall3n/react-hookie
🍪
https://github.com/jackall3n/react-hookie
Last synced: 4 months ago
JSON representation
🍪
- Host: GitHub
- URL: https://github.com/jackall3n/react-hookie
- Owner: jackall3n
- Created: 2019-06-12T09:46:12.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:33:30.000Z (over 1 year ago)
- Last Synced: 2025-02-04T22:06:41.628Z (5 months 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);
```