I'm trying to convert a component with state from class-based to functional, my state class looks like this:
class Person {
name:string = ""
email:string = ""
}
my class component looks like this:
class Component1 extends React.Component<{}, Person> {
state: Person = new Person();
foo() {
this.setState ({name:"me"});
}
}
you can see the setState call is only updating one property of the state. converting it to a functional component looks like this:
function Component() {
const [state, setState] = useState(new Person())
function foo() {
setState({name:"me"})
}
}
but I get a compilation error on the setState call
Argument of type '{ name: string; }' is not assignable to parameter of type 'SetStateAction<Person>'.
Property 'email' is missing in type '{ name: string; }' but required in type 'Person'.
Obviously the problem goes away if I use setState({...state, name:"me"}) but I don't want to have to do that if this is just a glitch in the TypeScript bindings.