Skip to content

Instantly share code, notes, and snippets.

@smably
Last active April 12, 2017 18:27
Show Gist options
  • Save smably/7550b9451682ff533b749f24aa57ca23 to your computer and use it in GitHub Desktop.
Save smably/7550b9451682ff533b749f24aa57ca23 to your computer and use it in GitHub Desktop.
react-portal bug on close
import React, { Component } from 'react';
import Portal from 'react-portal';
class PortalContents extends Component {
render () {
return <div onClick={this.props.closePortal}>close</div>;
}
componentDidMount() {
console.log('portal contents mounted');
}
componentWillUnmount() {
this.props.updateChildProp();
console.log('portal contents will unmount');
}
}
class App extends Component {
constructor(props) {
super(props);
this.state = { ok: true };
}
updateChildProp = () => {
console.log('child prop will update');
this.setState({ ok: false }, () => { console.log('updated child prop'); })
}
render() {
return (
<div className="App">
<Portal onClose={() => { console.log('portal closed'); }} openByClickOn={<div>open portal</div>}>
<PortalContents childProp={this.state.ok} updateChildProp={this.updateChildProp} />
</Portal>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment