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

199
Views
What is the type of the useState setter function?

Sometimes the setter function of a useState hook must be passed around. What is the right way to type that function?

// some component with useState
const [infoText, setInfoText] = useState<string>(""); 

// same component calls a function in which the setter function is needed.
getInfoText(setInfoText);

// in the definition of that function (getInfoText) I now want to correctly type the setter function
export function getInfoText(setInfoText: ???) {

P.S.: I know that there are a couple of similar questions. I want to provide a general question without context such as: what is the correct type for this piece of code.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The type of the state setter is like this:

React.Dispatch<React.SetStateAction<TypeOfTheState>>

For this one:

const [infoText, setInfoText] = useState<string>(""); 

setInfoText is of type:

React.Dispatch<React.SetStateAction<string>>
about 4 years ago · Juan Pablo Isaza 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!