3 ms·
> As you can see it becomes not that clean quickly. This is my biggest gripe with my fellow developers. Why they see the need of abstracting everything? I do
by bromuro 7y ago
> As you can see it becomes not that clean quickly.
This is my biggest gripe with my fellow developers. Why they see the need of abstracting everything?
I don't see any problem in this code:
```
const [count, setCount] = useState(0)
const [name, setName] = useState('')
const [school, setSchool] = useState('')
const [weight, setWeight] = useState(0)
const [height, setHeight] = useState(0)
```
but i see them in the proposed alternative:
```
function useFormState(initial) {
const [fields, setFields] = useState(initial)
const _setFields = (name, value) => {
if (name in fields) {
setFields({ ...fields, [name]: value })
}
}
return [ fields, _setFields ]
}
```
this kind of hooks likely are going to be extended in the future, supporting edge-cases, new features and so. But are these kind of abstraction necessary? Userland pushes them to the extreme with big packages.
All because the developer initially was seeing a "repeating pattern" in the code that was readable and testable.