React Fundamentals: State, Props, and Effects Explained

Most React tutorials teach syntax. useState here, useEffect there, props go down. What they don't teach is why React behaves the way it does. One idea fixes most of the confusion UI = function of state What's on screen is whatever your state says it should be. React doesn't manually update the DOM — it re-runs your component function on every state change and calculates what changed. Everything else follows from this. ⚠️ Why direct mutation does nothing user .name = "Harshal" // React doesn't see this React compares object references. Same reference, no re-render — doesn't matter what changed inside the object. setUser({ ...user, name: "Harshal" }) // new reference, React notices ⬇️ Why props only go downward Parent runs, passes data to children. Children can't push anything back up without a callback from the parent. The one-way flow isn't a limitation — it's what makes the data readable. 🔄 Why useEffect runs after the render React paints the screen first. Then effects run. Effects sync with the outside world — APIs, timers, subscriptions. If they ran before the paint, every render would wait on them. That's why the order is fixed. 🕳️ Why stale closures catch you off guard Your component captures state at the moment it runs. If state updates before a handler fires, the handler still holds the old value. That's just JavaScript closures working normally inside a re-render. Fix: put the value in the dependency array, or use a ref. #ReactJS #Frontend #JavaScript #WebDevelopment #FrontendDevelopment #ReactTips #SoftwareEngineering #DevCommunity

To view or add a comment, sign in

Explore content categories