Skip to content

Beginner problem with eventProxy #3947

Closed Answered by JoviDeCroock
sazarkin asked this question in Q&A
Discussion options

You must be logged in to vote

In your example you are passing a string to onClick rather than an actual reference, in backtick land we need to use ${} to pass a JS value. Note the added $ here right after onClick=, I also added ev to the onPlay arguments else it would crash.

import { h, Component, render } from 'https://esm.sh/preact@10.13.1';
import htm from 'https://esm.sh/v112/htm@3.1.1/es2022/htm.mjs';
const html = htm.bind(h);

class App extends Component {
  onPlay(ev) {
    ev.preventDefault();
    console.log('HERE');
  }

  render() {
    return html`<button onClick=${this.onPlay.bind(this)}>Click</button>`;
  }
}
render(html`<${App} />`, document.body);

updated Fiddle

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sazarkin
Comment options

Answer selected by JoviDeCroock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants