React Smart vs Dumb Components Design Pattern

⚛️ Top 150 React Interview Questions – 84/150 📌 Topic: Smart vs. Dumb Components ━━━━━━━━━━━━━━━━━━━━━━ 🔹 WHAT is it? Smart vs. Dumb Components is a design pattern that separates components by responsibility: 🧠 Smart (Container) Components Handle logic, state, API calls, and data management 🎨 Dumb (Presentational) Components Focus only on UI Receive data via props and display it ━━━━━━━━━━━━━━━━━━━━━━ 🔹 WHY use this pattern? ♻️ Reusability Dumb components are reusable because they don’t depend on business logic 🧪 Easy Testing UI components are easier to test when logic is separated 🧹 Cleaner Codebase Clear separation between how things work and how things look ━━━━━━━━━━━━━━━━━━━━━━ 🔹 HOW do you implement it? Keep logic in the parent (Smart) and pass data to the child (Dumb). Example: // SMART: Handles the logic function UserContainer() { const [user, setUser] = useState({ name: "Alex" }); return <UserProfile user={user} />; } // DUMB: Handles the UI function UserProfile({ user }) { return <h1>{user.name}</h1>; } ━━━━━━━━━━━━━━━━━━━━━━ 🔹 WHERE / Best Practices ✔ Keep Dumb Components Pure No useEffect, no API calls, no state logic ✔ Modern React Note With Hooks, the line is less strict — but the pattern is still very useful for keeping UI simple ━━━━━━━━━━━━━━━━━━━━━━ 📝 SUMMARY (Easy to Remember) Think of a restaurant 🍽️ 🧠 Smart Component → Kitchen (logic, cooking) 🎨 Dumb Component → Waiter (presenting food to the table) ━━━━━━━━━━━━━━━━━━━━━━ 👇 Comment “React” if this handbook is helping you 🔁 Share with someone preparing for React interviews #ReactJS #ReactInterview #ComponentDesign #SmartComponents #DumbComponents #Top150ReactQuestions #LearningInPublic #Developers ━━━━━━━━━━━━━━━━━━━━━━

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories