Skip to content

Instantly share code, notes, and snippets.

@nathggns
Forked from eldh/LazyRender.coffee
Last active August 29, 2015 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathggns/a5fce0957e8bae9ece9a to your computer and use it in GitHub Desktop.
Save nathggns/a5fce0957e8bae9ece9a to your computer and use it in GitHub Desktop.
module.exports = React.createClass({
displayName : 'LazyRender',
getInitialState() { return { props : this.props } },
componentWillReceiveProps(newProps) { setTimeout(() => this.setState(newProps), 10) },
shouldComponentUpdate(newProps, newState) { return this.state !== newState; },
render() { return React.cloneElement(React.Children.only(this.props.children), this.state); }
});
module.exports = React.createClass
displayName: 'LazyRender'
getInitialState: -> props: @props
componentWillReceiveProps: (newProps) -> setTimeout (=> @setState newProps), 10
shouldComponentUpdate: (newProps, newState) -> @state isnt newState
render: -> React.cloneElement React.Children.only(@props.children), @state
render: ->
LazyRender
prop1: 'thing'
prop2: 'another thing'
prop3: ['huge array', 'of', 'things']
, ExpensiveComponent()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment