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

375
Vistas
Setting formdata Object by using typescript

I have my Object state here written in vanilla javascript. and i wanted to convert it into typescript.

This is the state for formData object.

 const [formData, setFormData] = useState({
     firstName: "",
     lastName: "",  
 });

This is the handleFormChange function.

const handleFormChange = (event) => {
const { name, value } = event.target;
setForm(prevFormData => (
  ...prevFormData,
  [name]:value;
));

};

on vanilla js it's working perfectly fine. What could be the type definition for

[name]:value;

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Input OnChange Getting the value from an input onChange event is one of the first things people learn when working with HTML. In a Typescript environment, it can be tempting to use any as a type for the onChange event. Instead of any , you can useReact.ChangeEvent<HTMLInputElement>

const onChange = (event: React.ChangeEvent<HTMLInputElement>) =>
//That will give you access to all the values included in the input onChange event.

If you are using a text area and need to differentiate the event, you can use this instead:

const onChange = (event: React.ChangeEvent<HTMLTextAreaElement>) =>
about 4 years ago · Santiago Gelvez Denunciar

0

You should also share your setForm function here so I can try to answer your question based on that. Actually it would be even better if you could share your code with a CodeSandbox link. Btw this is not Vanilla JS, you use React's useState. I would suggest you to check React TypeScript CheetSheet.

about 4 years ago · Santiago Gelvez 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