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

233
Views
TypeScript - onChange event only accept ANY

I'm learning TS, and I don't understand why the event, when onChange execute, only accept "any".

I tried to change the event equal React.ChangeEventHandler, but still doesn't work:

  const onNameChange = (e: React.ChangeEventHandler<HTMLInputElement>) => {
    setField({ ...field, name: e.currentTarget.value });
  };

I think, some how, my event needs to be equal to my interface "CountProps". Follow the complete code:

import React, { useState } from "react";

interface FieldProps {
  name: string;
}

export const TextField: React.FC = () => {
  const [field, setField] = useState<FieldProps>({ name: "" });

  console.log(field);

  const onNameChange = (e: any) => {
    setField({ ...field, name: e.currentTarget.value });
  };

  return (
    <div>
      <input
        type="text"
        onChange={onNameChange}
        name="name"
        value={field.name}
      />
    </div>
  );
};

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

0

e is not the handler, it's the event. onNameChange is the handler

  const onNameChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
    setField({ ...field, name: e.currentTarget.value });
  };
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!