Skip to content

Instantly share code, notes, and snippets.

@eldh
Last active August 29, 2015 14:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eldh/5e671e2501e338064181 to your computer and use it in GitHub Desktop.
Save eldh/5e671e2501e338064181 to your computer and use it in GitHub Desktop.
Lazy render react component
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