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

138
Views
TS, ¿cómo puedo escribir esta función en una función de flecha?

¿Cómo puedo escribir esta función genérica con una función de flecha?

 function simpleState<T>(initial: T): [() => T, (v: T) => void] { let value: T = initial; return [ () => value, (v: T) => { value = v; } ] };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const simpleState = <T>(initial: T): [() => T, (v: T) => void] => { // same function body as before }

Dado que etiquetó react-native, tenga en cuenta que en un archivo .tsx , esto probablemente no funcionará, ya que la <T> se analizará como una etiqueta JSX. Puede ponerlo en un archivo .ts e importarlo a un archivo .tsx , o usar una de las siguientes soluciones para que no se interprete como un elemento JSX.

coma final:

 <T,>(initial: T): // etc

Extender desde desconocido:

 <T extends unknown>(initial: T): // etc
about 4 years ago · Juan Pablo Isaza Report

0

const simpleState2 = <T>(initial: T): [() => T, (v: T) => void] => { let value: T = initial; return [ () => value, (v: T) => { value = v; }, ]; }
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!