Last active
April 12, 2017 18:27
-
-
Save smably/7550b9451682ff533b749f24aa57ca23 to your computer and use it in GitHub Desktop.
react-portal bug on close
This file contains hidden or 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, { 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