1

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'})
    }
}
4
  • i dont know about typescript, but as i saw this code: blog.wolksoftware.com/working-with-react-and-typescript, i think instead of function keyword use public Commented Feb 3, 2017 at 10:04
  • @MayankShukla, handleImageChange isn't part of a Download class. I can use private handleImageChange and put it in the class but it's not a solution Commented Feb 3, 2017 at 10:06
  • i think u forgot to write this, try this: this.handleImageChange.bind(this) Commented Feb 3, 2017 at 10:07
  • @MayankShukla, I've tried, doesn't work. Edit code Commented Feb 3, 2017 at 10:10

1 Answer 1

1

This was fixed in preact-compat 3.13.1, released 2 days ago:

https://github.com/developit/preact-compat/releases/tag/3.13.1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.