You can use ReactDOM.createPortal to render a component in a new window as David Gilbertson explains in his post:
Answer from CD.. on Stack Overflowclass MyWindowPortal extends React.PureComponent { constructor(props) { super(props); // STEP 1: create a container <div> this.containerEl = document.createElement('div'); this.externalWindow = null; } render() { // STEP 2: append props.children to the container <div> that isn't mounted anywhere yet return ReactDOM.createPortal(this.props.children, this.containerEl); } componentDidMount() { // STEP 3: open a new browser window and store a reference to it this.externalWindow = window.open('', '', 'width=600,height=400,left=200,top=200'); // STEP 4: append the container <div> (that has props.children appended to it) to the body of the new window this.externalWindow.document.body.appendChild(this.containerEl); } componentWillUnmount() { // STEP 5: This will fire when this.state.showWindowPortal in the parent component becomes false // So we tidy up by closing the window this.externalWindow.close(); } }
GitHub
github.com › rmariuzzo › react-new-window
GitHub - rmariuzzo/react-new-window: 🔲 Pop new windows in React, using `window.open`.
Center popups according to the parent window or screen. ... import React from 'react' import NewWindow from 'react-new-window' const Demo = () => ( <NewWindow> <h1>Hi 👋</h1> </NewWindow> )
Starred by 464 users
Forked by 108 users
Languages JavaScript 98.4% | HTML 1.6%
Videos
00:43
How to Open Local Image in New Tab in React || Open Imported Image ...
05:47
Portals Can Share State Between Windows - YouTube
11:30
React Components | Tab View - Adding A New Tab - YouTube
04:00
How To Open A Link In A New Tab || React JS - YouTube
- YouTube
Top answer 1 of 7
35
You can use ReactDOM.createPortal to render a component in a new window as David Gilbertson explains in his post:
class MyWindowPortal extends React.PureComponent { constructor(props) { super(props); // STEP 1: create a container <div> this.containerEl = document.createElement('div'); this.externalWindow = null; } render() { // STEP 2: append props.children to the container <div> that isn't mounted anywhere yet return ReactDOM.createPortal(this.props.children, this.containerEl); } componentDidMount() { // STEP 3: open a new browser window and store a reference to it this.externalWindow = window.open('', '', 'width=600,height=400,left=200,top=200'); // STEP 4: append the container <div> (that has props.children appended to it) to the body of the new window this.externalWindow.document.body.appendChild(this.containerEl); } componentWillUnmount() { // STEP 5: This will fire when this.state.showWindowPortal in the parent component becomes false // So we tidy up by closing the window this.externalWindow.close(); } }
2 of 7
33
The upvoted answer works great!
Just leaving a function component version here in case people are searching for that in the future.
const RenderInWindow = (props) => {
const [container, setContainer] = useState(null);
const newWindow = useRef(null);
useEffect(() => {
// Create container element on client-side
setContainer(document.createElement("div"));
}, []);
useEffect(() => {
// When container is ready
if (container) {
// Create window
newWindow.current = window.open(
"",
"",
"width=600,height=400,left=200,top=200"
);
// Append container
newWindow.current.document.body.appendChild(container);
// Save reference to window for cleanup
const curWindow = newWindow.current;
// Return cleanup function
return () => curWindow.close();
}
}, [container]);
return container && createPortal(props.children, container);
};
npm
npmjs.com › package › react-new-window
react-new-window - npm
November 27, 2022 - Pop a new window in React, using window.open API. Latest version: 1.0.1, last published: 3 years ago. Start using react-new-window in your project by running `npm i react-new-window`. There are 25 other projects in the npm registry using react-new-window.
» npm install react-new-window
Published Nov 27, 2022
Version 1.0.1
Author Rubens Mariuzzo
Rmariuzzo
rmariuzzo.github.io › react-new-window
react-new-window - Default ⋅ Storybook
We cannot provide a description for this page right now
Scott Logic
blog.scottlogic.com › 2019 › 10 › 29 › popout-windows-in-react.html
Popout Windows in React
October 29, 2019 - import React from 'react'; import ReactDOM from 'react-dom'; interface Props { title: string; // The title of the popout window closeWindow: () => void; // Callback to close the popout } interface State { externalWindow: Window | null; // The popout window containerElement: HTMLElement | null; // The root element of the popout window } export default class Popout extends React.Component<Props, State> { constructor(props: Props) { super(props); this.state = { externalWindow: null, containerElement: null }; } // When we create this component, open a new window public componentDidMount() { const
CodeSandbox
codesandbox.io › examples › package › react-new-window
react-new-window examples - CodeSandbox
Use this online react-new-window playground to view and fork react-new-window example apps and templates on CodeSandbox.
npm
npmjs.com › package › @asutrick › react-new-window
@asutrick/react-new-window - npm
August 22, 2024 - Pop a new window in React, using window.open API. Latest version: 1.1.1, last published: a year ago. Start using @asutrick/react-new-window in your project by running `npm i @asutrick/react-new-window`. There are no other projects in the npm registry using @asutrick/react-new-window.
» npm install @asutrick/react-new-window
Published Aug 22, 2024
Version 1.1.1
Author Austin Sutrick
Repository https://github.com/asutrick/react-new-window
GitHub
github.com › RyanNerd › react-new-improved-window
GitHub - RyanNerd/react-new-improved-window: React New and Improved Window popup using the window.open API
If the title property is missing the new window will use the parent window's title. The features property no longer require height and width if not given and the center property is set then this will default to height: 600, width: 640. Note: Internet Explorer will no longer be supported. ... import React from 'react' import NewImprovedWindow from 'react-new-improved-window' const Demo = () => ( <Index> <h1>Hi 👋</h1> </Index> )
Starred by 15 users
Forked by 2 users
Languages TypeScript 50.3% | JavaScript 41.3% | HTML 6.9% | CSS 1.5% | TypeScript 50.3% | JavaScript 41.3% | HTML 6.9% | CSS 1.5%
npm
npmjs.com › package › rc-new-window
rc-new-window - npm
popup new browser window with react. Latest version: 0.1.13, last published: 4 years ago. Start using rc-new-window in your project by running `npm i rc-new-window`. There are 5 other projects in the npm registry using rc-new-window.
» npm install rc-new-window
Top answer 1 of 4
2
New Solution based on CreatePortal
import React, { useEffect, useCallback, useMemo, useState } from "react";
import { render, createPortal } from "react-dom";
const App = () => {
const [isOpen, setOpenState] = useState(false);
const open = useCallback(() => setOpenState(true));
const close = useCallback(() => setOpenState(false));
return (
<div>
<h1>Portals in React</h1>
<button onClick={open}>Open</button>
<button onClick={close}>Close</button>
{isOpen && (
<NewWindow close={close}>
Example <button onClick={close}>Close</button>
</NewWindow>
)}
</div>
);
};
const NewWindow = ({ children, close }) => {
const newWindow = useMemo(() =>
window.open(
"about:blank",
"newWin",
`width=400,height=300,left=${window.screen.availWidth / 2 -
200},top=${window.screen.availHeight / 2 - 150}`
)
);
newWindow.onbeforeunload = () => {
close();
};
useEffect(() => () => newWindow.close());
return createPortal(children, newWindow.document.body);
};
render(<App />, document.getElementById("root"));
2 of 4
1
This worked for me with React 18.
const secondaryWindow = window.open('', '_blank', 'width=600,height=400');
secondaryWindow.document.open();
secondaryWindow.document.write(`
<html>
<head>
<title>My Title</title>
</head>
<body>
<h2>My Header</h2>
<div id="scheduling-grid"></div>
</body>
</html>
`);
const secondaryRoot = secondaryWindow.document.getElementById('scheduling-grid');
const secondaryRootInstance = createRoot(secondaryRoot);
secondaryRootInstance.render(<RelevantComponent prop={prop} />)
Hacker News
news.ycombinator.com › item
Using React 16 to open new window with shared state | Hacker News
November 14, 2017 - That was I can abstract it into convenience classes for connecting, event listening, etc · You have three projects/clients/orders/enquiries/purchase orders/invoices/etc. You want to compare them/discuss them/etc
npm
npmjs.com › package › react-window
react-window - npm
February 13, 2026 - . Latest version: 2.2.7, last published: a month ago. Start using react-window in your project by running `npm i react-window`. There are 2396 other projects in the npm registry using react-window.
» npm install react-window
Published Feb 13, 2026
Version 2.2.7
Author Brian Vaughn
Repository https://github.com/bvaughn/react-window
Homepage https://react-window.vercel.app/
Stack Overflow
stackoverflow.com › questions › tagged › react-new-window
Newest 'react-new-window' Questions - Stack Overflow
June 17, 2025 - hey folks can anyone check my code because when I click on the login button new window opens up and immediately it closes I don't what the problem is I'm using import NewWindow from 'react-new-window';...
GitHub
github.com › rmariuzzo › react-new-window › issues
Issues · rmariuzzo/react-new-window
May 3, 2023 - 🔲 Pop new windows in React, using `window.open`. Contribute to rmariuzzo/react-new-window development by creating an account on GitHub.
Author rmariuzzo