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

Invalid hook call with React #190

Closed thelinuxlich closed 3 years ago

thelinuxlich commented 3 years ago

How am I supposed to use this library with React hooks? I'm getting "Invalid hook call" errors trying to use functional Components:


import { html } from 'htm/react'

const Form = props => {
  useEffect(() =< {
       // do something
  })
  return html`<form></form>`
}

// then on a index.html file
<div id="main"></div>
<script type="module">
  import htm from 'https://unpkg.com/htm?module'
  import React from 'https://cdn.skypack.dev/react'
  import reactDOM from 'https://cdn.skypack.dev/react-dom'
  import Form from './bundle.js'

  const html = htm.bind(React.createElement)
  reactDOM.render(
    html`
      <${Form} />
    `,
    document.getElementById('main')
  )
</script>
thelinuxlich commented 3 years ago

Nevermind, the issue is related to Rollup/Vite.