News for hackers. Stuff that matters.
Re:Two custom React hooks by loh on Friday December 17, 2021 @09:58PM (#29601148)
The docs you linked to are for class components (`this.setState`), not function components using hooks (`useState`).

From React's "Using the State Hook" docs:

> However, unlike this.setState in a class, updating a state variable always replaces it instead of merging it.

https://reactjs.org/docs/hooks-state.html#tip-using-multiple...

The `extendState` method gives you the same convenience of `this.setState` but with hooks in function components instead of class components.

Re:Two custom React hooks by drdec on Sunday December 19, 2021 @09:18AM (#29614120)
Thanks for the clarification.

I was replying to the poster who was using:

   setState({...state, a: 4})
and so I assumed they were already operating in a class component.