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

(Question) rebinding createElement on the fly #203

Closed rmorshea closed 3 years ago

rmorshea commented 3 years ago

I have a case where I want users of an application extension I'm developing to be able to specify what React they are using. So for example, instead of simply doing:

const html = htm.bind(React.createElement)

I would actually need to do:

let html;

function bindElementConstructor(createElement) {
    html = htm.bind(createElement);
}

// set a default constructor
bindElementConstructor(React.createElement);

// make this rebinding function available to users
export bindElementConstructor

function SomeComponent() {
    // no use the rebindable 'html' reference in a component
    return html`<div />`

Is such a thing possible?

rmorshea commented 3 years ago

Never mind, this doesn't actually solve my problem.