简体   繁体   中英

onChange is not triggered when i upload a image in react js

I want to upload a image in the react js I am sending property to a component like

<Input 
    changed={(event) => this.ChangedHandler(event)} 
    clicked={(event) => this.ClickedHandler(event)} 
 />

and i am receiving like from another functional component

const Input = (props) =>{
  return(
     <input
        onChange={props.changed} 
        onClick={props.clicked} 
    />
    <label>
        <input id="myFile" type="file"/>
        Upload File
    </label>
 )
}

when i was click while try to upload a image onClick event is triggered correctly, But choose the file for upload onChange should be triggered but that is not happen.

In your component Input you are not passing the props correctly. This is how you will do it.

<Input 
   changed={(event) => { this.ChangedHandler(event) }} 
   clicked={(event) => { this.ClickedHandler(event) }} 
/>

In your Input component file, you will do this.

const Input = (props) => {
  return(
    <input 
      type="file" 
      onChange={props.changed} 
      onClick={props.clicked} 
    >
      Upload
    </input>
   )
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM