developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.67k stars 170 forks source link

onClick isn't registering in functional component #193

Closed willmartian closed 3 years ago

willmartian commented 3 years ago

I am working on a Preact app using server side rendering and htm.

In the component below, I can't get the onClick handler to fire when clicked.

const HistoryListItem = ({ historyItem, key }) => {
    const handleClick = () => {
        console.log("test")
    }

    return html`
        <li onClick=${handleClick}>
            ${historyItem.toString()}
        </li>
    `;
}

I have tried onClick=${() => handleClick()} and onclick as well. I am coming from React, so I may be missing something super obvious. Any idea what is going on?

dy commented 3 years ago

It depends on what is html function here.

willmartian commented 3 years ago

It turns out I just didn't understand the implications of server side rendering! My error.