Nobody told me this when I started React. I learned props. I learned the state. I thought I understood both. I didn't. I was putting everything in state. User data. Config values. Things passed in from the parent. Didn't matter — if I needed it inside a component, it went into useState. It worked. Until it didn't. On a client project, I had a component receiving a userId from its parent. I was also storing that userId in local state. Then the parent updated. My local state didn't. Two different values. One component. Complete mess. The bug took me hours to find. The fix was deleting four lines of code. Here's what nobody told me: Props and state are not two ways to store data. They are two completely different things with two completely different jobs. Props are data that comes from outside. The parent owns it. The parent controls it. Your component just receives it and uses it. You don't store it. You don't copy it. You use it directly. State is data that lives inside. Your component owns it. Your component controls it. When it changes, the component re-renders. Nothing outside knows it exists unless you explicitly pass it down. One simple test I use now: Does this component own this data — or is it just receiving it from somewhere else? If it owns it → state. If it's receiving it → props. Use it directly. Never copy it into state. That one question has saved me from every props-vs-state bug I've ever faced. The bug I had on that client project? I was copying props into the state. The parent updated the prop. My state copy didn't follow. UI showed stale data. Classic mistake. Extremely common. Nobody warns you about it early enough. #React #JavaScript #Frontend #ReactJS #WebDevelopment #Programming #100DaysOfCode #SoftwareDevelopment
Props vs State in React: What Nobody Tells You
More Relevant Posts
-
🚀 5 React Mistakes I Made as a Beginner (And How to Fix Them) When I first started building with React, I made a lot of mistakes that slowed me down and introduced bugs I couldn't explain. Here are 5 of the most common ones — and how to fix them: ❌ #1 — Not cleaning up useEffect Forget to return a cleanup function? Hello, memory leaks. ✅ Always return a cleanup for timers, event listeners, and subscriptions. ❌ #2 — Using index as a key in lists This breaks React's reconciliation and causes weird UI bugs. ✅ Always use a unique ID from your data as the key prop. ❌ #3 — Calling setState directly inside render This creates an infinite re-render loop. ✅ Keep state updates inside event handlers or useEffect only. ❌ #4 — Fetching data without handling loading and error states Your UI breaks or shows nothing while data loads. ✅ Always manage three states: loading, error, and success. ❌ #5 — Putting everything in one giant component Hard to read, hard to debug, impossible to reuse. ✅ Break your UI into small, focused, reusable components. These mistakes cost me hours of debugging. I hope sharing them saves you that time. If you found this helpful, feel free to repost ♻️ — it might help another developer on their journey. 💬 Which of these mistakes have you made? Drop a comment below! #React #JavaScript #WebDevelopment #Frontend #MERNStack #ReactJS #100DaysOfCode #CodingTips #Developer
To view or add a comment, sign in
-
🧠 The bug wasn’t in my code… It was in my assumption. I spent 2 hours debugging a UI issue where a list wasn’t updating correctly. The logic looked fine. The API response was correct. State was updating. So what was wrong? 👇 👉 I was using the array index as the key in a dynamic list. At first, everything worked. But the moment I added/removes items… things broke in weird ways. 💥 Items re-rendered incorrectly 💥 State got mixed up between components 💥 UI started behaving unpredictably 💡 Lesson learned: Keys in React are not just for removing warnings. They are how React tracks identity. Using index as a key = telling React: "Yeah, these items might change… but pretend they didn’t." 🛠️ Better approach: Always use a unique and stable id from your data. 🧠 Simple way to think: React uses keys like names in a classroom. If everyone has the same name (or changing names), things get chaotic. 🔥 Takeaways: • Avoid index as key (especially in dynamic lists) • Stable identity = predictable UI • Many “random bugs” come from small decisions like this 💬 Have you ever faced a weird UI bug that turned out to be something small? #ReactJS #FrontendDevelopment #JavaScript #WebDev #CodingMistakes
To view or add a comment, sign in
-
𝗟𝗲𝘁’𝘀 𝘁𝗮𝗹𝗸 𝗮 𝗹𝗶𝘁𝘁𝗹𝗲 𝗯𝗶𝘁 𝗮𝗯𝗼𝘂𝘁 𝗡𝗼𝗱𝗲.𝗷𝘀! 𝐓𝐨𝐩𝐢𝐜 𝟏: 𝐓𝐡𝐞 𝐍𝐨𝐝𝐞.𝐣𝐬 𝐄𝐯𝐞𝐧𝐭 𝐋𝐨𝐨𝐩 It’s a meticulously ordered cycle of 6 steps - and most developers have never seen the part that goes between each one. ⚙️ 𝘛𝘩𝘦 6 𝘚𝘵𝘦𝘱𝘴: 1️⃣ 𝘛𝘪𝘮𝘦𝘳𝘴: Recalls setTimeout / setInterval whose delay has passed 2️⃣ 𝘈𝘸𝘢𝘪𝘵𝘪𝘯𝘨 callbacks: Recalls I/O errors that were rejected from the previous iteration 3️⃣ 𝘗𝘰𝘭𝘭𝘪𝘯𝘨: Retrieves new I/O events. This is where Node.js waits when idle. 4️⃣ 𝘊𝘩𝘦𝘤𝘬: setImmediate callbacks, always after Poll 5️⃣ 𝘊𝘭𝘰𝘴𝘦 𝘊𝘢𝘭𝘭𝘣𝘢𝘤𝘬𝘴: socket.on('close'), cleanup handlers 💠The hidden layer: microtasks Between each step, before the loop progresses, Node.js completely empties the microtask queue. Two subqueues, processed in exact order: ➡️ process.nextTick() callbacks - always first ➡️ Promise resolution callbacks - second This means that microtasks have a higher priority than any step of the Event Loop. 📌 𝘛𝘩𝘦 𝘳𝘶𝘭𝘦𝘴 𝘰𝘧 𝘵𝘩𝘶𝘮𝘣: ➡️ process.nextTick() is fired before Promises, even if Promise resolved first. ➡️ setImmediate() is always fired after I/O callbacks in the same iteration. ➡️ The order of setTimeout(fn, 0) and setImmediate() is not deterministic outside of I/O callbacks. ➡️ Never use nextTick() recursively in production code. The event loop is why Node.js can handle thousands of simultaneous connections on a single thread. Controlling its execution order is the difference between writing asynchronous code and understanding it. #nodejs #javascript #backend #eventloop #softwareengineering #webdevelopment
To view or add a comment, sign in
-
-
most developers don't know about the optional chaining operator gotcha. they use it everywhere. it silently hides bugs. the problem: optional chaining (?.) returns undefined if property doesn't exist. you think it's safe. bugs slip through. why it breaks: when you use optional chaining, you're not validating — you're hiding. undefined gets passed around. downstream code breaks. you spend 2 hours debugging something that should have failed immediately. the real issue: optional chaining makes bad data look safe. it lets undefined flow through your app like it's normal. the solution: validate early. fail loud. don't let undefined silently propagate. when to use optional chaining: - reading optional properties - not for safety - for convenience only when NOT to use it: - critical data paths - anything you depend on - anything that should always exist one rule: optional chaining is a convenience. validation is safety. use both. #reactjs #typescript #webdevelopment #buildinpublic #javascript
To view or add a comment, sign in
-
-
Most developers treat components like functions. Just input, output, done. But that thinking leads to a mess fast. What I was doing wrong: ❌ Putting everything in one giant component ❌ Fetching data directly inside UI components ❌ Ignoring the rules of hooks until bugs appeared ❌ Re-rendering everything because state lived in the wrong place What actually works: ✅ Separating concerns — UI, logic, and data each have a home ✅ Custom hooks to keep components clean and readable ✅ Lifting state only as high as it needs to go ✅ Memoization where it counts, not everywhere The real shift wasn't learning a new library or pattern. It was understanding that React rewards you for thinking about data flow before you write a single line of JSX. Your component tree is a reflection of how well you understand your data. Once I internalized that, debugging got easier, reviews got faster, and onboarding new teammates stopped being painful. React isn't hard. But writing React that other people can maintain? That takes intentional practice. Still learning. Still improving 🚀 #React #Frontend #WebDevelopment #JavaScript #SoftwareEngineering #ReactJS #CodeQuality
To view or add a comment, sign in
-
-
HOT TAKE: Full-stack TypeScript with tRPC is obsolete. Developers are moving to something even better. Why? Let's dive in. Is end-to-end type safety with tRPC a game-changer, or just another over-hyped tool? I've been building full-stack apps for a while, and the shift to TypeScript changed the game. tRPC seems like the natural evolution, promising type safety from the client to the server. But is it really delivering on that promise, or is it just making life more complicated? Using tRPC, I've seen significant improvements in how we manage API requests. Type inference across the stack makes debugging a breeze and helps catch errors at compile time rather than runtime. Here's a simple example that eliminates the usual middleman of REST: ``` import { createRouter } from '@trpc/server'; import { z } from 'zod'; export const appRouter = createRouter() .query('getUser', { input: z.string(), resolve({ input }) { return { id: input, name: 'User' + input }; } }); ``` No more endless back-and-forth between frontend and backend teams when something breaks. It’s all in sync. But here's the catch: it requires buy-in from the entire team and a push towards vibe coding to realize its full potential. Is it worth the initial investment in training and refactoring? I'm curious—how do you see the role of type-safe tools like tRPC in the evolution of web development? Are you seeing similar benefits, or do other pitfalls emerge? #WebDevelopment #TypeScript #Frontend #JavaScript
To view or add a comment, sign in
-
Most React tutorials are still teaching 2020 patterns. In 2026, the ecosystem has shifted dramatically: React 19 is stable, the compiler handles most memoization automatically, and useEffect should be a last resort — not your go-to for data fetching, derived state, or event responses. This guide walks you from project setup to production-ready patterns, with a cheat sheet you can bookmark. #react #web #frontend #next #frontend #performance #javascript #tips #typescript #nextjs
To view or add a comment, sign in
-
💡 𝗪𝗵𝘆 "𝗢𝗹𝗱 𝗦𝗰𝗵𝗼𝗼𝗹" 𝗩𝘂𝗲 𝗢𝗽𝘁𝗶𝗼𝗻𝘀 𝗔𝗣𝗜 𝗶𝘀 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗮 𝘀𝗲𝗰𝗿𝗲𝘁 𝘄𝗲𝗮𝗽𝗼𝗻 𝗳𝗼𝗿 𝘀𝘁𝗮𝗯𝗹𝗲 𝗲𝗻𝘁𝗲𝗿𝗽𝗿𝗶𝘀𝗲 𝘀𝘆𝘀𝘁𝗲𝗺𝘀. Unpopular opinion: I still prefer the Vue.js Options API for building complex information systems. 🚀 While the Composition API is fantastic for logic extraction and TypeScript flexibility, the structured nature of the Options API remains a "stability powerhouse" for long-term maintenance. Here’s why: 1️⃣ 𝗘𝗻𝗳𝗼𝗿𝗰𝗲𝗱 𝗣𝗿𝗲𝗱𝗶𝗰𝘁𝗮𝗯𝗶𝗹𝗶𝘁𝘆 In a massive information system, cognitive load is the enemy. With the Options API, I know exactly where to look for data, methods, and watchers. It’s an architectural "place for everything and everything in its place" approach that makes onboarding new developers a breeze. 2️⃣ 𝗥𝗲𝗮𝗱𝗮𝗯𝗶𝗹𝗶𝘁𝘆 𝗮𝘁 𝗦𝗰𝗮𝗹𝗲 When you’re dealing with hundreds of views and data-heavy forms, the clear separation of concerns (data, computed, methods) acts as a natural guide. It prevents the "spaghetti setup" that can sometimes happen when lifecycle hooks and state are mixed together without strict discipline. 3️⃣ 𝗧𝗵𝗲 "𝗜𝗳 𝗶𝘁 𝗮𝗶𝗻'𝘁 𝗯𝗿𝗼𝗸𝗲" 𝗙𝗮𝗰𝘁𝗼𝗿 Stable systems require stable patterns. Many of the enterprise tools we build today need to be maintainable for the next 5–10 years. The Options API is battle-tested, highly readable, and reduces the risk of over-engineering simple UI logic. Don't get me wrong—the Composition API is a game-changer for shared utility logic. But for the core "bread and butter" views of an information system? The Options API is still my go-to for speed and structural integrity. What’s your take? Are you fully "Setup" or do you still find value in the classic Options approach? 👇 #VueJS #WebDevelopment #Frontend #SoftwareArchitecture #Javascript #CleanCode #Programming
To view or add a comment, sign in
-
-
Nobody expects to fail these 7 React questions. And then they do. The tricky part? None of them are about some lesser-known API. They test whether you actually understand how React works under the hood. Here's what catches people off guard: 🔴 setState batching — calling setCount(count + 1) three times doesn't give you 3. It gives you 1. Closures are sneaky. 🟡 useRef vs useState — mutating a ref updates the value, but the UI never knows. It just sits there. Stale. 🔵 Stale closures in useEffect — an empty dependency array + setInterval = a timer that's frozen in time. Forever stuck at 1. 🟢 React.memo shallow trap — you wrapped your component in memo, feeling smart. But you're passing a new object literal every render. Memo does nothing. 🟣 useEffect cleanup order — most devs think cleanup only runs on unmount. Wrong. It runs before every single re-render effect. Every. Time. 🟡 Index as key — it works until you sort, filter, or reorder. Then React maps the wrong DOM to the wrong data. Inputs keep stale values. Good luck debugging that. 🔴 State mutation — you pushed to the array and called setState. React compared references. Same ref = no update. Your UI is frozen and you have no idea why. I put all 7 into a carousel with code snippets, wrong answers, correct answers, and explanations. Swipe through and test yourself honestly. The pattern? The questions that trip people up aren't about syntax. They're about understanding how React actually thinks. Save this for your next interview — whether you're giving it or taking it. --- #react #javascript #frontend #interviewprep #webdevelopment #softwareengineering #reactjs
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development