Created
February 10, 2020 00:19
-
-
Save EnetoJara/197419a696ff85a211c38111591ff25b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export class Son extends React.Component { | |
constructor (props) { | |
super(props); | |
this.state = { | |
message: "" | |
} | |
this.onChangeHandler = this.onChangeHandler.bind(this); | |
} | |
componentDidMount () { | |
// this route should only be avaleable from a popup | |
if (!window.opener) { | |
window.close(); | |
} | |
} | |
/** | |
* changes the value of the input. | |
* | |
* @param {import("react").ChangeEvent<HTMLInputElement>} evt | |
* @returns {void} | |
*/ | |
onChangeHandler (evt) { | |
const {value} = evt.currentTarget; | |
this.setState({message: value}); | |
// we use the `opener` object that lives on a parent window | |
// this object only exists if the current window has a child. | |
window.opener.onSuccess(value) | |
} | |
render () { | |
const {message} = this.state; | |
return ( | |
<div> | |
<input type="text" value={message} onChange={this.onChangeHandler} /> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment