Last active
October 5, 2017 20:09
-
-
Save danny-andrews/b56602077b4a3bcc793e4bc2378219d3 to your computer and use it in GitHub Desktop.
Render Callback Example
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
<div id="root"></div> |
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
class WindowWidth extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { width: 0 }; | |
} | |
componentDidMount() { | |
this.setState({ width: window.innerWidth }); | |
window.addEventListener( | |
'resize', | |
({ target }) => { | |
this.setState({ width: target.innerWidth }); | |
} | |
); | |
} | |
render() { | |
const { width } = this.state; | |
return this.props.children(width); | |
} | |
} | |
const App = () => ( | |
<WindowWidth> | |
{width => <div>Window is {width}</div>} | |
</WindowWidth> | |
); | |
ReactDOM.render(<App />, document.getElementById('root')); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/reselect.js"></script> |
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
.mouse { | |
height: 100vh; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment