React Cheat Sheet
React Cheat Sheet
7)
PAGE 1
React.createClass( ReactComponent|Specification
{PROPS}?
HTML Attributes
ReactClass
[CHILDREN...]?
ReactElement
JSX nodes desugar into createElement() calls, e.g. <Node /> becomes React.createElement(Node )
React.cloneElement( ReactElement
React.isValidElement( ReactElement
{PROPS}?
[CHILDREN...]?
ReactElement
Boolean
DOMElement
CALLBACK?
ReactComponent
ReactDOM.findDOMNode( ReactComponent
If this component has been mounted into the DOM, this returns the
corresponding native browser DOM element.
DOMElement
ReactDOM.unmountComponentAtNode( DOMElement
Boolean
String
ReactDOMServer.renderToStaticMarkup( ReactElement
CORE
METHODS
Component API
String
CALLBACK?
forceUpdate( CALLBACK?
render()
constructor(
Performs a shallow merge of nextState into current state and triggers UI update. Callback after update. NEVER mutate this.state.
void
Calling forceUpdate() will cause render() to be called on the component, skipping shouldComponentUpdate(). Avoid usage.
void
ReactElement|void|null
props
componentDidMount()
StateObject
void
shouldComponentUpdate( {NextProps}
componentWillUpdate( {NextProps}
componentDidUpdate( {PreviousProps}
void
componentWillReceiveProps( {NextProps}
componentWillUnmount()
void
{NextState}
void
{NextState}
{PreviousState}
Boolean
! Cannot use this.setState()
void
void
componentWillMount()
LIFECYCLE METHODS
HTMLElements
a abbr address area article aside audio b base bdi
bdo big blockquote body br button canvas caption
cite code col colgroup data datalist dd del details
dfn dialog div dl dt em embed fieldset figcaption
figure footer form h1 h2 h3 h4 h5 h6 head header
hgroup hr html i iframe img input ins kbd keygen
label legend li link main map mark menu menuitem
meta meter nav noscript object ol optgroup option
output p param picture pre progress q rp rt ruby
s samp script sec vvbvtion select small source
span strong style sub summary sup table tbody td
textarea tfoot th thead time title tr track u ul var
video wb
ReactClass
SupportedTags in JSX
SVGElements
circle clipPath defs ellipse g image line linearGradient
mask path pattern polygoN polyline radialGradient
rect stop svg text tspan
SVGAttributes
clipPath cx cy d dx dy fill fillOpacity fontFamily
fontSize fx fy gradientTransform gradientUnits
markerEnd markerMid markerStart offset
opacity patternContentUnits patternUnits points
preserveAspectRatio r rx ry spreadMethod stopColor
stopOpacity stroke strokeDasharray strokeLinecap
strokeOpacity strokeWidth textAnchor transform
version viewBox x1 x2 x xlinkAcvtuate xlinkArcrole
xlinkHref xlinkRole xlinkShow xlinkTitle xlinkType
xmlBase xmlLang xmlSpace y1 y2 y
JSX Events
Synthetic Event (default callback arg)
{
<ExampleComponent
key="uniqueValue"
/>
ref
<ExampleComponent
ref={ String|Callback
} />
dangerouslySetInnerHTML
<span
} />
void
...
<Component>{this.props.children}</Component>
void
var HelloMsg
Composition
DefaultPropertiesObject
This object defines the initial props values. It is cached and invoked
once when a class is instantiated.
ReactComponentClass.propTypes
PropertiesSpecificationObject
onCompositionEnd
onCompositionStart onCompositionUpdate
( String data )
Keyboard
ReactComponentClass.defaultProps
The PropertiesSpecificationObject can define the following property types (they are optional by default):
Clipboard
PROPERTIES
stopPropagation()
Boolean isPropagationStopped()
DOMEventTarget target
Number timeStamp
String type
Stateless Syntax
preventDefault()
Boolean isDefaultPrevented()
Provides the ability to insert raw HTML, mainly for cooperating with
DOM string manipulation libraries.
Boolean bubbles
Boolean cancelable
DOMEventTarget currentTarget
Boolean defaultPrevented
Number eventPhase
Boolean isTrusted
DOMEvent nativeEvent
React.PropTypes.array
React.PropTypes.bool
React.PropTypes.func
React.PropTypes.number
React.PropTypes.object
React.PropTypes.string
React.PropTypes.node (anything that can be rendered])
React.PropTypes.element (ReactElement)
React.PropTypes.instanceOf(Message) (must be of javascript type)
React.PropTypes.oneOf(['News', 'Photos']) (specify enumerated values)
React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number]) (limit property types)
React.PropTypes.arrayOf(React.PropTypes.number) (limit to a typed array)
React.PropTypes.objectOf(React.PropTypes.number) (limit to a typed object)
React.PropTypes.shape({color: React.PropTypes.string, fontSize: React.PropTypes.number}) (limit to object with specific keys/types)
React.PropTypes.func.isRequired (produce an error if the property isn't passed to the child)
React.PropTypes.any.isRequired (can be any object but must be required)
(props, propName, componentName) => Boolean (create a custom property with the following function signature)
onSelect
Touch
UI onScroll ( Number
detail, DOMAbstractView
view )
deltaMode,
deltaY, Number deltaZ )
onLoad onError