Home > Mobile >  How to set props type of "a useState function"?
How to set props type of "a useState function"?

Time:06-01

How to set props type of "a React useState function"

// ParentComponent.tsx

import { useState } from "react"
import ChildComponent "./ChildComponent"

const ParentComponent = () => {
  const [prompt, setPrompt] = useState<boolean>(false)
  return <ChildComponent setPrompt={setPrompt}/>
}

// ChildComponent.tsx

interface ChildComponentProps {
  setPrompt: Function // ✅ WORKED but inaccurate!
  setPrompt: (value: boolean) => void // kinda WORKED thanks @acemarke!
  setPrompt: typeof React.useState //            
  • Related