Skip to content

Instantly share code, notes, and snippets.

@mikeyamadeo
Created August 14, 2015 19:14
Show Gist options
  • Save mikeyamadeo/fbad832d0ff910079773 to your computer and use it in GitHub Desktop.
Save mikeyamadeo/fbad832d0ff910079773 to your computer and use it in GitHub Desktop.
imperative vs declarative functions w/ react
  renderThings () {
    return this.props.things.map(thing => {
      return <li>{thing.name}</li>
    })
  },

  render () {
    return (
      <ul>
        { this.renderThings() }
      </ul>
    )
  }
  

vs

  render () {
    const { props } = this
    return (
      <ul>
        { _renderThings(props) }
      </ul>
    )
  }
}

function _renderThings (props) {
  return this.props.things.map(thing => {
    return <li>{thing.name}</li>
  })
}
  
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment