I'm having a hard time figuring out the types when passing the useState setter function to a child component.
I've tried to simplify to just the essential code below:
parent
function Parent() {
const [name, setName] = useState("Structured")
..
return (
<>
<Child setName={setName}/>
</>
child
import { Dispatch, SetStateAction } from "react";
function Child(setName: Dispatch<SetStateAction<string>>){
return (
<>
<Input onChange={
(value)=>{
setName(value: SetStateAction<string>)
console.log(value)
}
</Input>
</>
On the parent I'm getting the following errors:
Type "{ setName: Dispatch<SetStateAction>; }' is not assignable to type ' IntrinsicAttributes & Dispatch<SetStateAction' Property 'setName' does not exist on type 'IntrinsicAttributes & Dispatch<SetStateAction>'.
On the child I'm getting:
Argument of type "string | string[]' is not assignable to parameter of type 'SetStateAction' Type "string[]' is not assignable to type "SetStateAction'