Need help with react-frame-component?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

ryanseddon
1.2K Stars 137 Forks MIT License 230 Commits 16 Opened issues

Description

Render your React app to an iFrame

Services available

!
?

Need anything else?

Contributors list

# 23,275
JavaScr...
React
tabular...
sketcha...
73 commits
# 47,282
TypeScr...
React
aws-lam...
datavis
34 commits
# 122,036
HTML
CSS
Webpack
Electro...
12 commits
# 3,520
React
JavaScr...
HTML
inputma...
4 commits
# 117,623
HTML
iframe
CSS
gui-fra...
4 commits
# 52,082
React
Shell
Webpack
React N...
4 commits
# 111,273
PHP
Laravel
hierarc...
Vue.js
4 commits
# 299,829
JavaScr...
React N...
React
HTML
4 commits
# 29,832
data-jo...
Shell
pixi
glsl
3 commits
# 20,673
JavaScr...
React
Electro...
css-in-...
3 commits
# 385,329
JavaScr...
React
HTML
iframe
2 commits
# 90,366
React
gatsby
mobx
CSS
2 commits
# 185,396
Shell
CSS
Redux
HTML
1 commit
# 438,846
PHP
React
HTML
iframe
1 commit
# 44,057
JavaScr...
CSS
reactjs
Shell
1 commit
# 15,168
Svelte
lodash
leaflet
React
1 commit
# 356,817
HTML
Shell
Redis
Lua
1 commit
# 452,353
JavaScr...
React
HTML
iframe
1 commit
# 1,247
ESLint
casperj...
cython
jython
1 commit
# 53,865
google-...
heatmap
angular...
leaflet...
1 commit

React <Frame /> component

NPM version Build Status Dependency Status

This component allows you to encapsulate your entire React application or per component in an iFrame.

npm install --save react-frame-component

How to use:

import Frame from 'react-frame-component';

Go check out the demo.

const Header = ({ children }) => (
  
    

{children}

);

ReactDOM.render(

Hello
, document.body);

Or you can wrap it at the

render
call.
ReactDOM.render(
  
    
Hello
, document.body );
Props:
head

head:  PropTypes.node

The

head
prop is a dom node that gets inserted before the children of the frame. Note that this is injected into the body of frame (see the blog post for why). This has the benefit of being able to update and works for stylesheets.
initialContent

initialContent:  PropTypes.string

Defaults to

'
'

The

initialContent
props is the initial html injected into frame. It is only injected once, but allows you to insert any html into the frame (e.g. a head tag, script tags, etc). Note that it does not update if you change the prop. Also at least one div is required in the body of the html, which we use to render the react dom into.
mountTarget

mountTarget:  PropTypes.string

The

mountTarget
props is a css selector (#target/.target) that specifies where in the
initialContent
of the iframe, children will be mounted.

contentDidMount and contentDidUpdate

contentDidMount:  PropTypes.func
contentDidUpdate:  PropTypes.func

contentDidMount
and
contentDidUpdate
are conceptually equivalent to
componentDidMount
and
componentDidUpdate
, respectively. The reason these are needed is because internally we call
ReactDOM.render
which starts a new set of lifecycle calls. This set of lifecycle calls are sometimes triggered after the lifecycle of the parent component, so these callbacks provide a hook to know when the frame contents are mounted and updated.
Accessing the iframe's window and document

The iframe's

window
and
document
may be accessed via the FrameContextConsumer.
import Frame, { FrameContextConsumer } from 'react-frame-component'

const MyComponent = (props, context) => ( { // Callback is invoked with iframe's window and document instances ({document, window}) => { // Render Children } }

);

More info

I wrote a blog post about building this component.

License

Copyright 2014, Ryan Seddon. This content is released under the MIT license http://ryanseddon.mit-license.org

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.