3 ms·
I like how it makes it possible to re-use behaviour among components, but I also really liked how classes encouraged structure and readability. My hunch is it'
by pastelsky 8y ago
I like how it makes it possible to re-use behaviour among components, but I also really liked how classes encouraged structure and readability.
My hunch is it's only a matter of time before someone creates a helper that would enable `useState` to take complex objects rather than calling it multiple times.
Also, custom hooks seem almost too powerful - easy to build multiple abstraction layers and make the API feel magical at the point of use.
- mhink 8y ago> My hunch is it's only a matter of time before someone creates a helper that would enable `useState` to take complex objects rather than calling it multiple times. You can already do that, although it's not _exactly_ the same as setState in a class (states aren't merged together... but if you really wanted to, it'd be about five lines to implement a custom hook) const [state, setState] = useState({ foo: "123", bar: "abc", }); function updateBar(nextBar) { setState({ ...state, bar: nextBar }); }