Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungWhy Claude Code keeps writing shell commands that fail on your Mac(20.09.2026 um 21:06 Uhr)
Sichere Programmierungllms.txt v2: What the Spec Says, and What 137,000 Domains Show(20.09.2026 um 21:17 Uhr)
Sicherheitslücken (CVE)NiceTryGPT: Less pattern matching. More actual hacking.(20.09.2026 um 21:19 Uhr)
IT Security VideoActivities BoF (kde2026)(20.09.2026 um 00:00 Uhr)
IT Security Toolsirdoc-app(20.09.2026 um 20:33 Uhr)
Sichere ProgrammierungWhy Claude Code keeps writing shell commands that fail on your Mac(20.09.2026 um 21:06 Uhr)
Sichere Programmierungllms.txt v2: What the Spec Says, and What 137,000 Domains Show(20.09.2026 um 21:17 Uhr)
Sicherheitslücken (CVE)NiceTryGPT: Less pattern matching. More actual hacking.(20.09.2026 um 21:19 Uhr)
IT Security VideoActivities BoF (kde2026)(20.09.2026 um 00:00 Uhr)
IT Security Toolsirdoc-app(20.09.2026 um 20:33 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

When do (and don’t) children re-render in React?

Reagiere als Erste:r — dein Feedback zählt!

When writing React components, we always strive to keep optimization in mind. It’s always useful to know when unnecessary re-rendering occurs in our code, especially if we have heavy components in our app.

So let’s dive in and see what happens with child components when their parents re-render.

In most cases we use child components by their name. Let’s examine the following code:

import { useState } from "react";

const Parent = () => {
  const [number, setNumber] = useState(0);

  console.log('<Parent> renders');

  return (
    <div>
      Number is {number}
      <div>
        <button onClick={() => setNumber(prev => prev + 1)}>
          Increment
        </button>
      </div>
      <Child />
    </div>
  );
};

const Child = () => {
  // Some time-consuming logic
  console.log('<Child> renders');

  return (
    <div>
      <div>Child component</div>
    </div>
  );
};

const App = () => {
  return (
    <Parent />
  );
};

export default App;

Every time the button is pressed, the state of the <Parent /> component changes and it re-renders, which causes re-rendering <Child /> component as well.

How can we prevent unnecessary re-renders for the Child component? Let’s explore two approaches to achieve this.

Approach 1: Our friend React.memo

If we wrap the Child component into React.memo, the Parent’s re-render will not cause the Child to re-render.

Quick reminder — React.memo memoizes components, ensuring they are not re-rendered when their props remain unchanged.

import { memo, useState } from "react";

const Parent = () => {
  const [number, setNumber] = useState(0);

  console.log('<Parent> renders');

  return (
    <div>
      Number is {number}
      <div>
        <button onClick={() => setNumber(prev => prev + 1)}>
          Increment
        </button>
      </div>
      <Child />
    </div>
  );
};

const Child = memo(() => {
  // Some time-consuming logic
  console.log('<Child> renders');

  return (
    <div>
      <div>Child component</div>
    </div>
  );
});

const App = () => {
  return (
    <Parent />
  );
};

export default App;

Approach 2: Using {children} prop

We can use {children} prop to achieve the same result. Let’s see it in action.

{children} prop allows the parent component to accept and render its children components dynamically.

import {useState} from "react";

const Parent = ({children}) => {
  const [number, setNumber] = useState(0);

  console.log('<Parent> renders');

  return (<div>
    Number is {number}
    <div>
      <button onClick={() => setNumber(prev => prev + 1)}>
        Increment
      </button>
    </div>
    {children}
  </div>);
};

const Child = () => {
  // Some time-consuming logic
  console.log('<Child> renders');

  return (
    <div>
      <div>Child component</div>
    </div>
  );
};

const App = () => {
  return (
    <Parent>
      <Child />
    </Parent>
  );
};

export default App;

Using children prop here makes the code easier to follow, and also removes extra clutter coming from memo.

While these two approaches help us remove unnecessary re-rendering child components, bear in mind that we don’t need to blindly optimize everything. If our component doesn’t involve heavy calculations or other performance bottlenecks, we usually shouldn’t prematurely optimize it. Always strive to keep components small and easy to follow, and optimize them only when necessary.

Thanks for reading! If you have any notes, remarks or questions, please share them in the comments.

Stay updated with the latest JavaScript and software development news! Join my Telegram channel for more insights and discussions: TechSavvy: Frontend & Backend.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten When do (and don’t) children re-render in React?

Thematisch verwandte Begriffe: When, dont, children, rerender · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93956 | A flaw has been found in olivier-ls PHP-FTS up to 1.1.2. Affected by thi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick