Open wangyfax opened 3 years ago
Hello, I was facing the same problem but I managed to sort myself out with the onUnload
prop.
Example of a component that opens any number of windows onclick and retains their data.
const TestMultiple = () => {
const [windows, setWindows] = React.useState<null[]>([]);
const [otherWindowInput, setInput] = React.useState('');
return (
<>
<p>Here's the input from another window</p>
<p>{otherWindowInput}</p>
<button onClick={() => setWindows((prev) => [...prev, null])}>Click me to open a new window! Wowsers</button>
{windows.map((_) => (
<NewWindow onUnload={() => setWindows((prev) => prev.slice(1))}>
<h1>WOW</h1> <input onChange={(e) => setInput(e.target.value)}></input>
</NewWindow>
))}
</>
);
};
It should click on the same place many times as you would on a browser, and multiple windows will be opened. However, it seems that this function is not supported at present. Or maybe there is something wrong with my usage?