Skip to content

Instantly share code, notes, and snippets.

@frederickfogerty
Created January 5, 2016 22:56
Show Gist options
  • Save frederickfogerty/20fecab9c11d3fbb670f to your computer and use it in GitHub Desktop.
Save frederickfogerty/20fecab9c11d3fbb670f to your computer and use it in GitHub Desktop.
// old way
import React from 'react'
var App = React.createClass({ // ew, an object
componentWillMount: function () {}, // ew, commas needed
render: function() {
return <div />
}
})
// React 0.13 way
import React, { Component } from 'react'
class App extends Component {
componentWillMount = () => {} // no commas needed. = () => needed for this binding
render () {
return <div />
}
}
// Added in React 0.14: Stateless components. Only works if pure i.e. only uses props
import React from 'react'
const App = props => <div />
App.displayName = 'App' // Needed to show name in React Dev Tools
// Add export default to any of the above to export them
// 0.12 (two options)
export default App // preferred
export default React.createClass()
// 0.13 (two options)
export default class App extends Component {} // preferred
export default App
// 0.14 (two options)
export default App // preferred
export default props => <div />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment