Home > Enterprise >  passing file as prop in react typescript (Type 'true' is not assignable to type 'Chan
passing file as prop in react typescript (Type 'true' is not assignable to type 'Chan

Time:01-16

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

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)

CodePudding user response:

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

onChange=={upload_id_card}
  •  Tags:  
  • Related