Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

passing file as prop in react typescript (Type 'true' is not assignable to type 'ChangeEventHandler<HTMLInputElement>)

I am writing an application with reactjs

I want to upload file which is passed as a prop from child component to parent component

Child Component

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const RegisterIndividual: React.FC< { upload_id_card: React.ChangeEventHandler<HTMLInputElement>} > = ({
  upload_id_card,
  handleInput }) => {

  return (
    <div className="mt-3">

          <input
            type="file"
            name="profile_picture"
            id=""
            onChange=={upload_id_card}
            style={{ display: "block", marginTop: "1rem" }}
          />
     </div>
)};

Parent Component

const Register = () => {
const upload_id_card = (event) => {
    console.log("type upload file code here")
  }
  return (
    <div className="__register">
    <RegisterIndividual upload_id_card={upload_id_card} />
    </div>
)}

but I am getting this error on the child component

Type 'true' is not assignable to type 'ChangeEventHandler<HTMLInputElement> | undefined'.ts(2322)

>Solution :

Remove the == and replace with =, you want to assign and not compare:

onChange=={upload_id_card}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading