ryanseddon / react-frame-component

Render your React app to an iFrame
http://ryanseddon.github.io/react-frame-component/
MIT License
1.74k stars 156 forks source link

Add beforeRender hook with iframe document passed #55

Closed srigi closed 7 years ago

srigi commented 7 years ago

Hi, I really like the idea of styletron. This thing allows really nice concept of components' styles. However this also needs a raw <style> element to be mounted to the DOM before rendering. With this components this cannot be achieved now - style element must be attached to the iframe's DOM, not the host page.

But by inserting this

this.props.beforeRender(doc);

before this line will do the trick. That way I will be able to do:

const styleSheet = document.createElement('style');
const styletron = new Styletron(styleSheet);

<Frame
  beforeRender={(doc) => {  // exposing iframe document
    doc.head.appendChild(styleSheet);
  }}
>
  <StyletronProvider styletron={styletron}>
    <MyApp />
  </StyletronProvider>
</Frame>

Are you willing to accept PR?

darthtrevino commented 7 years ago

I think you'll be able to do this using the new context values for document and window. Check the example for how to access those

srigi commented 7 years ago

Thanks, will check it out.