hardFrontend

How do you optimize React component rendering?

929 views
01

Understand the problem

Demonstrates an understanding of performance best practices.

performanceoptimizationmemoizationreact.memo
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Move state down so siblings don't re-render
import { useState } from "react";

// ✅ state lives inside SearchBox, so typing doesn't re-render <ExpensiveList/>
function SearchBox() {
  const [q, setQ] = useState("");
  return <input value={q} onChange={(e) => setQ(e.target.value)} placeholder="search" />;
}
function ExpensiveList() {
  console.log("list rendered");        // not re-rendered on each keystroke
  return <ul><li>item</li></ul>;
}

export default function App() {
  return (
    <div style={{ padding: 24, fontFamily: "system-ui" }}>
      <SearchBox />
      <ExpensiveList />
    </div>
  );
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.