Top-Level API Flashcards
React.Component
The base class for React Components defined with ES6 classes.
React.createClass()
Create a component class
params: specification
returns: ReactClass
specification
an object that defines (at least) a render method
React.createElement()
Creates a ReactElement… either an html tag or a ReactClass. This is equivalent to JSX
params: type[, props[, children …]]
returns: ReactElement
- type Either a string for tag name, or an object for ReactClass - props object with the props to pass in - children child elements
React.cloneElement()
Clones the element with shallow merge for props. Key and ref from original element are preserved.
params: element[, props[, children …]]
returns: ReactElement
- element element to clone - props object with the props to pass in - children child elements
React.createFactory()
Return a function that produces ReactElements of a given type
params: type
returns: factoryFunction
- type
HTML string or ReactClass
React.isValidElement()
Verify that object is ReactElement
params: element
returns: boolean
React.DOM
Convenience wrappers around React.createElement for DOM components
React.PropTypes
A list of types that can be used to validate the props being passed in
React.Children
convenience functions for dealing with the this.props.children opaque data structure
React.children.map()
Returns an array of the children with fn applied
params: children, fn[, thisArg]
returns: array | null | undefined
Note: if children is a nested object, it will be traversed. fn will not be passed the container
React.Children.forEach()
Runs the function against all children
params: children, fn[, thisArg]
React.Children.count()
Counts the children (based oh how many times map fn would be called)
params: children
returns: number
React.Children.only()
Return the only child in children. Throw otherwise
params: children
React.Children.toArray()
Return the children data structure as an array. Use to manipulate collections in render methods (e.g reorder or slice)
ReactDOM
DOM-specific methods that can be used at the top level of an app (to go outside the React model if needed)