Last active
September 22, 2015 21:48
-
-
Save jide/b4c954392735719ea7f2 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'; | |
class Slice extends Component { | |
static propsTypes = { | |
children: PropTypes.func.isRequired | |
} | |
render() { | |
return this.props.children(); | |
} | |
} | |
class Badge extends React.Component { | |
render() { | |
console.log('Badge: render'); | |
return ( | |
<div>{ this.props.title }</div> | |
); | |
} | |
} | |
class App extends React.Component { | |
constructor(...args) { | |
super(...args); | |
this.slices = {}; | |
this.state = { | |
title: 'initial' | |
}; | |
} | |
shouldComponentUpdate() { | |
return false; | |
} | |
handleWrapperClick() { | |
this.setState({ | |
title: 'updated wrapper', | |
test: 10 | |
}, () => this.slices.wrapper && this.slices.wrapper.forceUpdate()); | |
} | |
handleInnerClick() { | |
this.setState({ | |
title: 'updated inner' | |
}, () => this.slices.inner && this.slices.inner.forceUpdate()); | |
} | |
render() { | |
console.log('App: render'); | |
return ( | |
<Slice ref={ ref => this.slices.wrapper = ref }> | |
{ () => ( | |
<div> | |
<button onClick={ ::this.handleWrapperClick }>Update wrapper</button> | |
<button onClick={ ::this.handleInnerClick }>Update inner</button> | |
<Slice ref={ ref => this.slices.inner = ref }> | |
{ () => <Badge title={ this.state.title }/> } | |
</Slice> | |
</div> | |
) } | |
</Slice> | |
); | |
} | |
} | |
const content = document.getElementById('content'); | |
React.render(<App/>, content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment