← Back to Chapters

React Native Lifecycle Methods

? React Native Lifecycle Methods

? Quick Overview

Lifecycle methods in React Native describe the different phases a component goes through from creation to removal. Understanding these phases helps manage data fetching, subscriptions, UI updates, and cleanup efficiently.

? Key Concepts

  • Lifecycle methods exist mainly in class components.
  • Functional components use useEffect to handle lifecycle behavior.
  • Each phase controls rendering, updating, and unmounting logic.

? Syntax / Theory

  • Mounting Component creation and insertion into UI
  • Updating State or props change
  • Unmounting Component removal
? View Code Example
// React Native class component lifecycle example
import React from "react";
import { Text, View } from "react-native";

class LifeCycleDemo extends React.Component {

componentDidMount() {
// Runs once after component is mounted
console.log("Component Mounted");
}

componentDidUpdate() {
// Runs after every update
console.log("Component Updated");
}

componentWillUnmount() {
// Cleanup before component is removed
console.log("Component Will Unmount");
}

render() {
// UI rendering logic
return (

Lifecycle Methods

);
}
}

export default LifeCycleDemo;

? Live Output / Explanation

When the component loads, componentDidMount runs first. On state or prop changes, componentDidUpdate executes. Before removal, componentWillUnmount handles cleanup.

? Interactive Lifecycle Flow

Click the simulator buttons below to see the corresponding phase highlight here.

Mount Update Unmount

?️ Interactive Lifecycle Simulator

Simulate a React Native Component lifecycle. Watch the console logs and the diagram above.

12:00 PM • 100%
No Component
// Console Logs

? Use Cases

  • Fetching API data on component load
  • Updating UI on state change
  • Removing timers or listeners safely

? Tips & Best Practices

  • Prefer functional components with hooks for modern apps
  • Always clean up subscriptions in unmount phase
  • Avoid heavy logic inside render()

? Try It Yourself

  1. Create a component and log lifecycle methods
  2. Trigger updates using state changes
  3. Observe logs during component removal