react-new-window icon indicating copy to clipboard operation
react-new-window copied to clipboard

Cannot open the same window more than once

Open wangyfax opened this issue 4 years ago • 1 comments

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?

wangyfax avatar Nov 24 '20 08:11 wangyfax

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>
      ))}
    </>
  );
};

JoaquimEsteves avatar Nov 24 '20 09:11 JoaquimEsteves