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

[solved] Question: How use htm locally with es-react #196

Closed gurpal2000 closed 3 years ago

gurpal2000 commented 3 years ago

Referring to the htm/es-react examples on https://www.npmjs.com/package/es-react :

I want a local copy of import htm from 'https://unpkg.com/htm?module' (ie. no going online per page hit)

If i fetch it via npm, and try to reference the node_modules version, I see the error "The requested module './js/node_modules/htm/preact/standalone.module.js' does not provide an export named 'default'"

If i download the output of the unpkg.com via curl, i'm able to make things work.

I've tried all sorts of combinations, eg preact/standalone.module.js react/index.module.js etc

Please advise. Thanks

gurpal2000 commented 3 years ago

solved:

<script type="module">
import htm from './js/node_modules/htm/dist/htm.module.js'
import { React, ReactDOM } from './js/node_modules/es-react/dev'

const html = htm.bind(React.createElement)

    ReactDOM.render(
      html`
        <p>hello</p>
      `,
      document.getElementById('app')
    )
</script>