When you develop your own projects, searching on the internet for React documentation and APIs or going back to this book’s chapters to find a single method isn’t efficient. If you’d like to save time and avoid the distractions lurking everywhere on the Net, use this React cheatsheet as a quick reference.
In addition to the text version presented here, I’ve created a free beautifully designed, print-ready PDF version of this cheatsheet. You can request this PDF at http://reactquickly.co/resources.

ReactDOM.render(
React.createElement(
Link,
{href: 'https://Node.University'}
)
),
document.getElementById('menu')
)
ReactDOM.render(
<Link href='https://Node.University'/>,
document.getElementById('menu')
)
const ReactDOMServer = require('react-dom/server')
ReactDOMServer.renderToString(Link, {href: 'https://Node.University'})
ReactDOMServer.renderToStaticMarkup(Link, {href: 'https://Node.University'})
var Link = React.createClass({
displayName: 'Link',
render: function() {
return React.createElement('a',
{className: 'btn', href: this.props.href}, 'Click ->', this.props.href)
}
})
var Link = React.createClass({
render: function() {
return <a className='btn' href={this.props.href}>Click ->
this.props.href</a>
}
})
class Link extends React.Component {
render() {
return <a className='btn' href={this.props.href}>Click ->
this.props.href</a>
}
}
var Link = React.createClass ({
propTypes: { href: React.PropTypes.string },
getDefaultProps: function() {
return { initialCount: 0 }
},
getInitialState: function() {
return {count: this.props.initialCount}
},
tick: function() {
this.setState({count: this.state.count + 1})
},
render: function() {
return React.createElement(
'a',
{className: 'btn', href: '#', href: this.props.href,
onClick: this.tick.bind(this)},
'Click ->',
(this.props.href ? this.props.href : 'https://webapplog.com'),
' (Clicked: ' + this.state.count+')'
)
}
})
var Link = React.createClass ({
propTypes: { href: React.PropTypes.string },
getDefaultProps: function() {
return { initialCount: 0 }
},
getInitialState: function() {
return {count: this.props.initialCount};
},
tick: function() {
this.setState({count: this.state.count + 1})
},
render: function() {
return (
<a onClick={this.tick.bind(this)} href="#" className="btn"
href={this.props.href}>
Click -> {(this.props.href ? this.props.href :
'https://webapplog.com')}
(Clicked: {this.state.count})
</a>
)
}
})
export class Link extends React.Component {
constructor(props) {
super(props);
this.state = {count: props.initialCount};
}
tick() {
this.setState({count: this.state.count + 1});
}
render() {
return (
<a onClick={this.tick.bind(this)} href="#" className="btn"
href={this.props.href}>
Click -> {(this.props.href ? this.props.href :
'https://webapplog.com')}
(Clicked: {this.state.count})
</a>
)
}
}
Link.propTypes = { initialCount: React.PropTypes.number }
Link.defaultProps = { initialCount: 0 }
|
Mounting |
Updating component properties |
Updating component state |
Using forceUpdate() |
Unmounting |
|---|---|---|---|---|
| getDefaultProps() | ||||
| getInitialState() | ||||
| componentWillMount() | ||||
| componentWillReceiveProps() | ||||
| shouldComponentUpdate() | shouldComponentUpdate() | |||
| componentWillUpdate() | componentWillUpdate() | componentWillUpdate() | ||
| render() | render() | render() | render() | |
| componentDidUpdate() | componentDidUpdate() | componentDidUpdate() | ||
| componentDidMount() | ||||
| componentWillUnmount() |
Types available under React.PropTypes:
To make a property required (warning only), append .isRequired.
More methods:
propTypes: {
customProp: function(props, propName, componentName) {
if (!/regExPattern/.test(props[propName])) {
return new Error('Validation failed!');
}
}
}
As npm modules: