Skip to content

Instantly share code, notes, and snippets.

@EnetoJara
Created February 10, 2020 00:19
Show Gist options
  • Save EnetoJara/197419a696ff85a211c38111591ff25b to your computer and use it in GitHub Desktop.
Save EnetoJara/197419a696ff85a211c38111591ff25b to your computer and use it in GitHub Desktop.
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