Signature
Type Parameters
object
default:"{}"
The props type for the component.
object
default:"{}"
The state type for the component.
Constructor
Instance Properties
props
children and optional ref.
state
setState().
context
Core Methods
setState
state: Object to merge into state, or updater function receiving previous state and propscallback: Optional function called after state update and re-render complete
src/component.js:34
forceUpdate
shouldComponentUpdate.
Parameters:
callback: Optional function called after re-render completes
src/component.js:69
render
Usage Examples
Basic Component
With TypeScript
Lifecycle Methods
shouldComponentUpdate Optimization
Error Boundaries
Context Consumer
Lifecycle Method Order
Mounting
constructor()static getDerivedStateFromProps()render()componentDidMount()
Updating
static getDerivedStateFromProps()shouldComponentUpdate()render()getSnapshotBeforeUpdate()componentDidUpdate()
Unmounting
componentWillUnmount()
Error Handling
static getDerivedStateFromError()componentDidCatch()
Legacy Lifecycle Methods
These methods are still supported but deprecated:componentWillMount()- UsecomponentDidMount()orconstructor()componentWillReceiveProps()- UsegetDerivedStateFromProps()orcomponentDidUpdate()componentWillUpdate()- UsegetSnapshotBeforeUpdate()orcomponentDidUpdate()
Implementation Details
The Component class is implemented insrc/component.js:19 as BaseComponent:
Performance Notes
setStateuses shallow merging and batches multiple calls- Re-renders are scheduled asynchronously via microtasks
forceUpdatebypassesshouldComponentUpdateoptimization- State updates within
setStatecallback see the updated state
Related APIs
render- Mount components to the DOMFragment- Group multiple childrencreateContext- Create context for component treehooks- Modern alternative to class components