2 ms·
> 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 ti
by 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 });
}