Using React v16.1, on a local development server. I have a simple component to upload a file here:
class FileImporter extends React.Component {
constructor(props) {...}
importFile(e) {
// import the file here, not firing
}
render() {
return (<input type="file" onChange={this.importFile.bind(this)} />);
}
}
The function importFile
never fires. I've tried binding onChange
in the following ways:
onChange={e => this.importFile(e)}
onChange={this.importFile.bind(this)}
onChange={this.importFile}
I've tried using react-file-reader-input
and react-file-reader
, and just a raw input tag like in the snippet. None of them fire the onChange handler.
The system file upload dialog shows up, but on selecting a file nothing happens.
How can I get the onChange event to fire?