New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-window-opener

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-window-opener

A small reactjs utility to make sure that window.open actually opens popup and cominecate with the parent window.opner

latest
Source
npmnpm
Version
0.0.7
Version published
Weekly downloads
33
-50.75%
Maintainers
1
Weekly downloads
 
Created
Source

react-window-opener

A small reactjs utility to make sure that window.open actually opens popup and cominecate with the parent window.opener

NPM JavaScript Style Guide

Why I may use this

If you are using React and opening a window popup for any reason like Google authentication, for example, you will need to pass the data back to the parent page. but as you are using react you can't access the function in your page components via 'window.opener'،

Demo

https://ahakem.github.io/react-window.opener/#/

Install

npm install react-window-opener

or

yarn add react-window-opener

Usage for React App

Parent Page


import WindowOpener from 'react-window-opener'

export default function Example  {
    const childResponse = (err, res) => {
    if (err) {
      console.log(res, 'err')
    }
    console.log(res, 'res')
  }
    return (
      <WindowOpener url='/popUp-URL' bridge={childResponse}>
      )
}

Child Page (The PopUp)

just pass the needed data using window.opener.onSuccess(state)

export default function SmallWindow() {
  const [state, setstate] = useState('')
  const update = (evt) => {
    setstate(evt.target.value)
    window.opener.onSuccess(state)
  }
  return (
    <>
      <input value={state} onChange={update} />
      <button
        onClick={() => {
          window.close()
        }}
      >
        Close Me
      </button>
    </>
  )
}

How To use it in NextJs App

All you need to import it like that more info here

import dynamic from 'next/dynamic'
const WindowOpener = dynamic(() => import('react-window-opener'), { ssr: false })

Props

ParamsValueDefault ValueDescription
urlstringREQUIREDthe url for the page which will open in the popup
bridgefunctionREQUIREDFunction to handel the result that you will pass from the child popup
widthnumber300PopUp Width
heightnumber400PopUp Height
classNameEmpty

License

MIT © ahakem

credits

The idea came from this repo with some enhancment EnetoJara/window-opener

FAQs

Package last updated on 14 Jun 2020

Did you know?

Socket

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.

Install

Related posts