easyFrontend

Explain the concept of 'unidirectional data flow' in React.

792 views
01

Understand the problem

Describe what unidirectional data flow means in React and its implications for application architecture.

data flowstate managementarchitectureprops
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

Child requests change via a callback
import { useState } from "react";

function LikeButton({ count, onLike }) {     // receives data + callback (down)
  return <button onClick={onLike}>👍 {count}</button>; // calls up, never mutates
}

export default function App() {
  const [likes, setLikes] = useState(0);     // owner of the state
  return (
    <div style={{ padding: 24, fontFamily: "system-ui" }}>
      <LikeButton count={likes} onLike={() => setLikes((n) => n + 1)} />
      <p>Total likes: {likes}</p>
    </div>
  );
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

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