zouhir / preact-habitat

Zero configuration Preact widgets renderer in any host DOM
MIT License
518 stars 43 forks source link

Asynchronously added widget not showing up #35

Open gijo-varghese opened 5 years ago

gijo-varghese commented 5 years ago

I'm using the widget inside a modal and several other components in a react project. So when the render function executes it could not find the widgets since it's still not added to the dom.

Can I call render function again? If so how is it? Is it the right method?

gijo-varghese commented 5 years ago

For now what I've done is:

import habitat from "preact-habitat";
import Root from "./Root";

window.render = () => {
  habitat(Root).render({
    ...
  });
};

// in development, set up HMR:
if (module.hot) {
  require("preact/devtools"); // enables React DevTools, be careful on IE
  module.hot.accept("./Root", () => requestAnimationFrame(init)); // eslint-disable-line
}

window.render();

So later in my React components, I can use window.render()

gijo-varghese commented 5 years ago

@zouhir can you pls take a look when you're free?