
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@dimetrix/react-iframe
Advanced tools
A fully configurable React component that renders React components inside an isolated iframe
A fully configurable React component that renders React components inside an isolated iframe with complete style isolation and full React functionality.
component propnpm install @dimetrix/react-iframe
Peer Dependencies:
react ^17.0.0 || ^18.0.0 || ^19.0.0react-dom ^17.0.0 || ^18.0.0 || ^19.0.0import { ReactIframe } from '@dimetrix/react-iframe';
import MyComponent from './MyComponent';
function App() {
return (
<ReactIframe
component={MyComponent}
width="100%"
height="400px"
sandbox="allow-scripts allow-same-origin"
/>
);
}
import { ReactIframe } from '@dimetrix/react-iframe';
function App() {
return (
<ReactIframe width="100%">
<MyComponent />
</ReactIframe>
);
}
Note:
autoHeightis enabled by default, so noheightprop is needed.
The ReactIframe component extends all standard HTML iframe attributes and adds the following props:
| Prop | Type | Default | Description |
|---|---|---|---|
component | ComponentType<Record<string, unknown>> | - | React component to render inside the iframe (alternative to children) |
children | ReactNode | - | React component(s) to render inside the iframe (alternative to component) |
componentProps | Record<string, unknown> | {} | Props to pass to the component rendered inside the iframe |
autoHeight | boolean | true | Automatically adjust iframe height to match content height (enabled by default) |
minHeight | number | 0 | Minimum height in pixels when autoHeight is enabled |
maxHeight | number | undefined | Maximum height in pixels when autoHeight is enabled |
...iframeProps | React.IframeHTMLAttributes | - | All standard HTML iframe attributes |
Note: Either
componentorchildrenmust be provided, but not both.
All standard HTML iframe attributes are supported and passed through:
Common Attributes:
sandbox - Security sandbox attributes (e.g., "allow-scripts allow-same-origin")allow - Feature policy (e.g., "camera; microphone; geolocation")allowFullScreen - Allow fullscreen modereferrerPolicy - Referrer policy ("no-referrer", "strict-origin-when-cross-origin", etc.)loading - Lazy loading ("lazy" or "eager")name - Frame namewidth, height - Dimensions (ignored when autoHeight is true)title - Accessibility titleclassName, style - StylingEvent Handlers:
onLoad - Fired when iframe loadsonError - Fired on iframe erroronFocus, onBlur - Focus eventsData & ARIA Attributes:
data-* attributesaria-* attributesimport { ReactIframe } from '@dimetrix/react-iframe';
import Counter from './Counter';
function App() {
return (
<ReactIframe
component={Counter}
width="100%"
height="300px"
sandbox="allow-scripts allow-same-origin"
title="Counter Component"
/>
);
}
import { ReactIframe } from '@dimetrix/react-iframe';
import UserProfile from './UserProfile';
function App() {
return (
<ReactIframe
component={UserProfile}
componentProps={{
userId: 123,
showEmail: true,
theme: 'dark'
}}
width="100%"
height="500px"
/>
);
}
import { ReactIframe } from '@dimetrix/react-iframe';
import DynamicContent from './DynamicContent';
function App() {
return (
<ReactIframe
component={DynamicContent}
width="100%"
minHeight={200}
maxHeight={1000}
// autoHeight is enabled by default
sandbox="allow-scripts allow-same-origin"
/>
);
}
The autoHeight prop automatically adjusts the iframe height to match its content, preventing vertical scrollbars. This is especially useful for dynamic content that changes size.
import { ReactIframe } from '@dimetrix/react-iframe';
import MyComponent from './MyComponent';
function App() {
const handleLoad = (event: React.SyntheticEvent<HTMLIFrameElement>) => {
console.log('Iframe loaded successfully', event);
};
const handleError = (event: React.SyntheticEvent<HTMLIFrameElement>) => {
console.error('Iframe error', event);
};
return (
<ReactIframe
component={MyComponent}
width="600px"
height="400px"
sandbox="allow-scripts allow-same-origin allow-forms"
allow="camera; microphone; geolocation"
referrerPolicy="no-referrer"
loading="lazy"
title="My Isolated Component"
className="my-iframe-class"
style={{ border: '2px solid #ccc', borderRadius: '8px' }}
onLoad={handleLoad}
onError={handleError}
data-testid="my-component-iframe"
aria-label="Isolated React component"
/>
);
}
import { ReactIframe } from '@dimetrix/react-iframe';
function App() {
return (
<ReactIframe
width="100%"
height="400px"
componentProps={{ initialCount: 10 }}
>
{(props) => <Counter initialCount={props.initialCount} />}
</ReactIframe>
);
}
ResizeObserver and MutationObserver to detect content size changes and adjust the iframe height accordinglyEmbed React components as isolated widgets in third-party websites without style conflicts.
Test or preview components in isolation without affecting the parent application.
Render components with their own CSS that won't interfere with the parent page styles.
Display content that changes size dynamically with automatic height adjustment.
Full TypeScript support is included. Import types as needed:
import { ReactIframe, ReactIframeProps } from '@dimetrix/react-iframe';
// Use the type for props
const props: ReactIframeProps = {
component: MyComponent,
width: '100%',
height: '400px',
autoHeight: true,
};
Works in all modern browsers that support:
ResizeObserver (for auto-height feature, with fallback for older browsers)See the example/ directory for a complete demo application showcasing:
To run the example:
cd example
npm install
npm run dev
When using the sandbox attribute, ensure you include allow-same-origin if you need to access the iframe's content:
// β
Good - allows script execution and same-origin access
sandbox="allow-scripts allow-same-origin"
// β May not work - too restrictive
sandbox="allow-scripts"
sandbox includes allow-same-origin if usedResizeObserver with a fallback to polling for older browsersrequestAnimationFrame throttlingcomponentProps are passed directly to your componentcomponentProps will trigger re-renders inside the iframeIf you see warnings about not being able to access iframe content:
sandbox attribute - ensure allow-same-origin is includedautoHeight={true} is setsandbox includes allow-same-originminHeight to see if the feature is workingStyles inside the iframe are isolated. If you need to share styles:
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)Made with β€οΈ for the React community
FAQs
A fully configurable React component that renders React components inside an isolated iframe
The npm package @dimetrix/react-iframe receives a total of 20 weekly downloads. As such, @dimetrix/react-iframe popularity was classified as not popular.
We found that @dimetrix/react-iframe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.