Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
TS how can I this function write to a arrow function?

How can I write this generic function with a arrow function ?

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 Respuestas
Responde la pregunta

0

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

Since you tagged react-native, be aware that in a .tsx file, this will probably not work, since the <T> will be parsed as being a JSX tag. You can either put it in a .ts file, and import it into a .tsx file, or use one of the following workarounds to get it to not be interpreted as a JSX element.

Trailing comma:

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

Extend from unknown:

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda