Code Reference

Class Component Methods

React · Methods reference

React · Methods reference


📋 Overview

Legacy class component lifecycle and instance API (prefer hooks for new code).

🔧 Methods

Lifecycle methods

MethodDescription
constructor(props)Initialize state; bind handlers
render()Return React elements (required)
componentDidMount()After first paint
componentDidUpdate(prevProps, prevState)After update
componentWillUnmount()Cleanup before remove
shouldComponentUpdate(nextProps, nextState)Return false to skip render
getDerivedStateFromProps(props, state)Static — sync state from props
getSnapshotBeforeUpdate(prevProps, prevState)Capture DOM before update
componentDidCatch(error, info)Error boundary handler

Instance

Property / methodDescription
this.state / this.setState(updater, callback?)State read/update
this.propsRead-only props
this.forceUpdate()Force re-render

💡 Examples

See parent topic notes for runnable snippets; this page is the complete method index.

⚠️ Pitfalls

  • Mutating methods return None in Python — do not chain sort() / reverse() expecting a new list.
  • Default JS sort() compares strings — pass (a,b) => a-b for numbers.
  • SQL function names differ by dialect — verify Postgres vs MySQL docs.
  • Django QuerySet.update() skips save() signals and auto auto_now fields on models.

On this page