1
onChange
イベントがpreact
で動作しないという問題が発生しました。 react
ではすべてがうまく動作します。 onInput
も機能しません。 (preact
+ typescript
)preact:入力ファイルでOnChangeが機能しない
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'})
}
}
私は知りません私はこのコードを見ました:http://blog.wolksoftware.com/working-with-react-and-typescript、 'function'キーワードの代わりに' public'を使うと思います –
@MayankShukla、 'handleImageChange' 'Downloadクラス'の一部ではありません。私は 'private handleImageChange'を使ってクラスに入れてもいいですが、解決策ではありません。 –
' this'を書くのを忘れてしまったと思います。 'this.handleImageChange.bind(this)' –