Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
how to pass useState set state function to a child component in typescript?

I recently started using typescript and I'm having trouble with passing a use state setter function,

my parent component is is this :

const [word, setword] = useState('run')

and in the child im passing :

<Child word={word} setword={setword}/>

the child has this :

    interface Props {
      word: string
      
      setword: React.Dispatch<React.SetStateAction<string>>;
    }
    const VoicetoText: React.FC<Props> = (word, setword) => {
    return (
{word}
<button onClick={()=>setword('hey buddy')} ><button/>
    )}

i keep getting an error :enter image description here

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

You forgot to add a curly brace to

const VoicetoText: React.FC<Props> = (word, setword) 

either use props or deconstruct the props

const VoicetoText: React.FC<Props> = (props) 
props.setWord

deconstruct

const VoicetoText: React.FC<Props> = ({word, setword}) 
about 4 years ago · Santiago Gelvez Report

0

I would suggest to not make your life harder and go wtih something like:

const Child = ({setWord}: {setWord: (arg0: string}) => void) => {
  // () => setWord("word") is jsut for sample sake, you should avoid using arrow function calls inside event handleres like this
  return <button onClick={() => setWord("word")}>Click me</button>
}

const Parent = () => {

  const [word, setWord] = useState(false);

  return <Child propName={setWord}/>
}
about 4 years ago · Santiago Gelvez Report

0

Just use setword: (word: string) => void as the prop type.

interface Props {
  word: string      
  setword: (word: string) => void;
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!