This page contains a detailed API reference for the React component class definition. It assumes you’re familiar with fundamental React concepts, such as Components and Props, as well as State and Lifecycle. If you’re not, read them first. Show
OverviewReact lets you define components as classes or functions. Components defined as classes currently provide more features which are described in detail on this page. To define a React component class, you need to extend
The only method you must define in a We strongly recommend against creating your own base component classes. In React components, code reuse is primarily achieved through composition rather than inheritance.
The Component LifecycleEach component has several “lifecycle methods” that you can override to run code at particular times in the process. You can use this lifecycle diagram as a cheat sheet. In the list below, commonly used lifecycle methods are marked as bold. The rest of them exist for relatively rare use cases. MountingThese methods are called in the following order when an instance of a component is being created and inserted into the DOM:
UpdatingAn update can be caused by changes to props or state. These methods are called in the following order when a component is being re-rendered:
UnmountingThis method is called when a component is being removed from the DOM:
Error HandlingThese methods are called when there is an error during rendering, in a lifecycle method, or in the constructor of any child component.
Other APIsEach component also provides some other APIs:
Class Properties
Instance Properties
ReferenceCommonly Used Lifecycle MethodsThe methods in this section cover the vast majority of use cases you’ll encounter creating React components. For a visual reference, check out this lifecycle diagram.
|