React.Component is the base class for React components when they are defined using ES6 classes:

class Greeting extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}
React.Suspense lets you specify the loading indicator in case some components in the tree below it are not yet ready to render. Today, lazy loading components is the only use case supported by :

// This component is loaded dynamically
const OtherComponent = React.lazy(() => import('./OtherComponent'));

function MyComponent() {
  return (
    // Displays <Spinner> until OtherComponent loads
    <React.Suspense fallback={<Spinner />}>
      <div>
        <OtherComponent />
      </div>
    </React.Suspense>
  );
}
Furthermore, React.PureComponent’s shouldComponentUpdate() skips prop updates for the whole component subtree. Make sure all the children components are also “pure”.

const MyComponent = React.memo(function MyComponent(props) {
  /* render using props */
});
The React.Fragment component lets you return multiple elements in a render() method without creating an additional DOM element:

render() {
  return (
    <React.Fragment>
      Some text.
      <h2>A heading</h2>
    </React.Fragment>
  );
}
React.createRef creates a ref that can be attached to React elements via the ref attribute.

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();  }
}
Returns the total number of components in children, equal to the number of times that a callback passed to map or forEach would be invoked.

React.Children.only(children)
You can learn how to use it from our code splitting documentation. You might also want to check out this article explaining how to use it in more detail.

// This component is loaded dynamically
const SomeComponent = React.lazy(() => import('./SomeComponent'));
Unlike the shouldComponentUpdate() method on class components, the areEqual function returns true if the props are equal and false if the props are not equal. This is the inverse from shouldComponentUpdate.

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

I figured that since this.refs.bar is an instance of Bar, I can use findDOMNode to obtain a reference to the rendered element.


import React from 'react';
import ReactDOM from 'react-dom';

export default (Bar) => {
    return class Foo extends React.Component {
        componentDidMount = () => {
            console.log(ReactDOM.findDOMNode(this.refs.bar));
        };

        render() {
            return <Bar ref='bar' {... this.props} />;
        }
    }
};

Recommend

React Passing Functions to Components How can I prevent a function from being called too quickly or too many times in a row? requestAnimationFrame throttling

React Passing Functions to Components How can I prevent a function from being called too quickly or too many times in a row? Debounce

React Passing Functions to Components How can I prevent a function from being called too quickly or too many times in a row? Throttle

React Passing Functions to Components How do I pass a parameter to an event handler or callback? Example: Passing params using data-attributes

React Passing Functions to Components How do I pass a parameter to an event handler or callback?

React Passing Functions to Components Why is my function being called every time the component renders?

React Passing Functions to Components Why is binding necessary at all?

React Passing Functions to Components How do I bind a function to a component instance? Arrow Function in Render

React Passing Functions to Components How do I bind a function to a component instance? Class Properties (Stage 3 Proposal)

React Passing Functions to Components How do I bind a function to a component instance? Bind in Constructor (ES2015)

React Passing Functions to Components How do I pass an event handler (like onClick) to a component?

React Building Your Own Hooks useYourImagination()

React Building Your Own Hooks Using a Custom Hook Tip: Pass Information Between Hooks

React Building Your Own Hooks Using a Custom Hook

React Building Your Own Hooks Extracting a Custom Hook

React Building Your Own Hooks

React Conditional Rendering Preventing Component from Rendering

React Conditional Rendering Inline If-Else with Conditional Operator

React Conditional Rendering Inline If with Logical && Operator

React Conditional Rendering Element Variables

React Conditional Rendering

React Composition vs Inheritance Specialization

React Composition vs Inheritance Containment

React Using the State Hook Recap Tip: Using Multiple State Variables

React Using the State Hook Recap Tip: What Do Square Brackets Mean?

React Using the State Hook Recap

React Using the State Hook Updating State

React Using the State Hook Reading State

React Using the State Hook Declaring a State Variable

React Using the State Hook What’s a Hook?

React Using the State Hook Hooks and Function Components

React Using the State Hook Equivalent Class Example

React Using the State Hook

React Handling Events Passing Arguments to Event Handlers

React Handling Events

React Hello World

React Rules of Hooks Explanation

React Rules of Hooks ESLint Plugin

React Introducing Hooks

ReactDOMServer Reference renderToStaticNodeStream()

ReactDOMServer Reference renderToNodeStream()

ReactDOMServer Reference renderToStaticMarkup()

ReactDOMServer Reference renderToString()

ReactDOMServer

React Testing Recipes Multiple Renderers

React Testing Recipes Snapshot Testing

React Testing Recipes Timers

React Testing Recipes Events

React Testing Recipes Mocking Modules

React Testing Recipes Data Fetching

React Testing Recipes Rendering

React Testing Recipes act()

React Testing Recipes Setup/Teardown

React Rendering Elements Updating the Rendered Element

React Rendering Elements Rendering an Element into the DOM

React Rendering Elements

React Component State What is the difference between passing an object or a function in setState?

React Component State Why is setState giving me the wrong value?

React Refs and the DOM Callback Refs