Created
January 5, 2016 22:56
-
-
Save frederickfogerty/20fecab9c11d3fbb670f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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