React Top-Level API

React Top-Level API

React is the entry point to the React library. If you load React from a 'script' tag, these top-level APIs are available on the React global.

React.createElement()

React.createElement(
  type,
  [props],
  [...children]
)

Create and return a new React element of the given type (the type argument can be either a tag name string (such as 'div' or 'span'), a React component type (a class or a function), or a React fragment type).

React.cloneElement()

React.cloneElement(
  element,
  [props],
  [...children]
)

Clone and return a new React element using element as the starting point.

The resulting element will have the original element’s props with the new props merged in shallowly. New children will replace existing children. key and ref from the original element will be preserved.

React.createFactory()

React.createFactory(type)

Return a function that produces React elements of a given type.

Like React.createElement(), the type argument can be either a tag name string (such as 'div' or 'span'), a React component type (a class or a function), or a React fragment type.

React.isValidElement()

React.isValidElement(object)

Verifies the object is a React element, returns true or false.

React.createRef

class MyComponent extends React.Component {
  constructor(props) {
    super(props);

    this.inputRef = React.createRef();
  }

  render() {
    return <input type="text" ref={this.inputRef} />;
  }

  componentDidMount() {
    this.inputRef.current.focus();
  }
}

Creates a ref that can be attached to React elements via the ref attribute.

React Top-Level API — Structure map

Clickable & Draggable!

React Top-Level API — Related pages: