I've encountered with a problem that onChange event in preact doesn't work. In react everything works fine though. onInput doesn't work either.
Example of dumb code that must work (preact + typescript)
export class Download extends React.Component<DownloadProps, {}> {
constructor(props: DownloadProps) {
super(props);
this.state = {
imgSrc: ''
};
}
public componentDidUpdate() {
console.log('did2')
}
public render() {
console.log('render', this.state);
return <div className={s.root}>
<input className='fileInput' type='file' onChange={() => { this.handleImageChange() }} />
<div className={s.comment}>Upload</div>
</div>;
}
private handleImageChange() {
this.setState({imgSrc: '30'})
}
}
functionkeyword usepublichandleImageChangeisn't part of aDownload class. I can useprivate handleImageChangeand put it in the class but it's not a solutionthis, try this:this.handleImageChange.bind(this)