How I Understood useState When I first saw useState, it looked scary. Brackets. Functions. Weird syntax 😅 Then I stopped thinking like a developer and thought like a human. I asked myself: 👉 What is state in real life? State is just memory. A counter remembers a number. An input remembers text. A button remembers whether it’s clicked or not. That’s exactly what useState does. It tells React: 🧠 “Hey, remember this value. And when it changes, update the UI.” That’s it. No magic. So now I think of useState like this: One variable → current value One function → update the value Change the state → React re-renders → UI updates. Big lesson for me 👇 Don’t memorize syntax. Understand the idea behind it. Still learning. Still building. 🚀 #ReactJS #useCallback #FrontendDeveloper #LearningInPublic #Frontend #LearningInPublic #JavaScript #WebDevelopment #DeveloperJourney
Understanding useState in React: State as Memory
More Relevant Posts
-
Why can’t we create a state variable outside the component function? const [count, setCount] = React.useState(0); ❌ function Counter() { return <div>{count}</div>; } function Counter() { const [count, setCount] = React.useState(0); ✅ return <div>{count}</div>; } Why? Because Hooks rely on the component’s render cycle. When React renders a component, it: 1️⃣ Calls the component function 2️⃣ Tracks the order of Hooks 3️⃣ Stores state internally based on that order Hooks are tightly connected to the component’s lifecycle. If you declare state outside: ❌ There is no render context ❌ No component lifecycle ❌ React can’t track it #ReactJS #ReactHooks #ReactInternals #FrontendDevelopment #JavaScript #SoftwareEngineering #WebDevelopment #LearningInPublic #ReactInterview #FrontendEngineer #TechInterview
To view or add a comment, sign in
-
𝗔 𝗥𝗲𝗮𝗰𝘁 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗜 𝗖𝗮𝗺𝗲 𝗔𝗰𝗿𝗼𝘀𝘀 𝗥𝗲𝗰𝗲𝗻𝘁𝗹𝘆 Imagine you have a component rendering a list of 5,000 users. Every time the parent component updates, the entire list re-renders. The UI starts lagging. What would you try first to optimize it? Possible approaches: 1️⃣ Wrap the list component with React.memo 2️⃣ Use useMemo for the filtered data 3️⃣ Virtualize the list using libraries like react-window 4️⃣ Move state closer to where it’s used Which approach would you try first — and why? Continuing Day 5 — sharing interesting React interview questions I come across. #ReactJS #FrontendInterviews #JavaScript #FrontendDevelopment
To view or add a comment, sign in
-
Another core concept in React is props, short for “properties.” Props are how data moves from one component to another. Think of them as inputs you pass into a component so it can display or use that data. For example, you might have a reusable component that displays a user card. Instead of hardcoding the name or email inside the component, you pass that information in as props. The component stays flexible, and you can reuse it in different places with different data. This pattern is what makes React applications easier to organize. Small components receive data through props, render what they need, and stay focused on a single job. Once you start thinking in terms of components passing data through props, building larger interfaces becomes much more manageable. #reactjs #webdevelopment #frontenddevelopment #javascript #softwaredevelopment
To view or add a comment, sign in
-
-
Today I revisited an important concept in React.js — the Component Lifecycle. Understanding the lifecycle of a component is essential for writing efficient and maintainable React applications. Every React component goes through a series of phases during its lifetime. Key Lifecycle Phases: • Mounting – When the component is created and inserted into the DOM. • Updating – When the component re-renders due to changes in state or props. • Unmounting – When the component is removed from the DOM. In traditional Class Components, lifecycle methods such as componentDidMount, componentDidUpdate, and componentWillUnmount were used to manage these phases. With Functional Components and React Hooks, particularly useEffect(), managing lifecycle-related logic has become simpler and more readable. Mastering the React lifecycle helps developers: ✔ Handle side effects like API calls ✔ Optimize component performance ✔ Write cleaner and more predictable code Learning React is not only about building components, but also about understanding how they behave throughout their lifecycle. #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #ReactLifecycle #ReactHooks #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
Something new I learned about React today… I thought setState() updates immediately. But React batches state updates. Example: 👉 setCount(count + 1); 👉 setCount(count + 1); You might expect +2… But it becomes +1. Why? React queues updates and processes them together in the next render cycle. Both calls use the same previous count value. Why does React do this? Because DOM updates are expensive. Batching helps: ✅ Reduce unnecessary re-renders ✅ Improve performance ✅ Keep UI updates efficient Correct way when depending on previous state: 👉 setCount(prev => prev + 1); 👉 setCount(prev => prev + 1); 💡 Realization: State updates are scheduled, not instant. #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #SoftwareEngineering #CodingJourney #LearningInPublic #DeveloperLife #ReactInternals #FrontendEngineer #TechInterview #StateManagement
To view or add a comment, sign in
-
Most developers learn randomly. Smart developers follow a roadmap. Frontend in 2026 is not just React. It’s architecture, performance, and deployment. If you master these 6 branches, you’re no longer “just frontend”. You’re valuable. Learn from: 📚 Roadmap: https://lnkd.in/dySCRmV 📺 Free Full Course: https://lnkd.in/dF6WuxXW 📘 JavaScript Deep Dive: https://javascript.info 💬 Which branch are you currently learning? SAVE this roadmap. Build with clarity. #Connexode #FrontendDeveloper #WebDevelopment #ReactJS #NextJS #JavaScript #CodingJourney
To view or add a comment, sign in
-
-
How I Understood useRef When I first saw useRef, I thought: “Okay… is this another useState?” 😅 But then I noticed something strange. I changed a value. The UI didn’t re-render. Nothing refreshed. And that’s when it clicked 💡 👉 useRef is like a sticky note. It remembers a value… but doesn’t shout to React about it. useState says: “Hey React! I changed. Update the UI!” useRef says: “Just remember this quietly.” That’s why I use useRef for: Accessing DOM elements (input focus, scroll) Storing previous values Timers, intervals, and mutable data The big lesson for me 👇 Not every change needs a re-render. Now when I choose between useState and useRef, I ask one question: 👉 Should the UI update or not? Still learning. Still simplifying. 🚀 #ReactJS #useCallback #FrontendDeveloper #LearningInPublic #Frontend #LearningInPublic #JavaScript #WebDevelopment #DeveloperJourney
To view or add a comment, sign in
-
-
How React Remembers State Between Renders? When a component re-renders, the function runs again from top to bottom. So how does useState not reset every time? 🤔 function Counter() { const [count, setCount] = React.useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; } Every render: The function runs again and Variables are recreated. So why doesn’t count go back to 0? What Actually Happens Internally React stores state outside the component function. Behind the scenes: 1) Each component has a Fiber node 2) React keeps a linked list of Hooks 3) It tracks Hooks based on call order State is not stored in your function. It’s stored in React’s internal Fiber system. The function is just a way for React to describe UI. Understanding this makes Hooks feel much less magical. #ReactJS #ReactInternals #ReactHooks #FrontendDevelopment #SoftwareEngineering #JavaScript
To view or add a comment, sign in
-
-
Why React Re-Renders (And Why That’s Not Always Bad) One of the most common things I hear about React: “It’s re-rendering again.” And it’s usually said like… something is broken. But here’s the truth: Re-renders are not the enemy. They’re how React works. 🔁 What Actually Triggers a Re-Render? A component re-renders when: - Its state changes - Its props change - Its parent re-renders That’s it. React doesn’t randomly re-render your components. It responds to change. 😅 The Misconception Many developers try to prevent every re-render using: - useMemo - useCallback - React.memo But here’s the question: Are the re-renders actually expensive? Because most of the time… They’re not. React’s reconciliation is fast. Rendering a few components again usually costs almost nothing. ⚠️ When Re-Renders Become a Problem Re-renders matter when: - You’re rendering large lists - Heavy computations run on every render - Expensive child components re-render unnecessarily That’s when optimization makes sense. Not before. 🧠 The Mental Shift Instead of asking: “How do I stop this from re-rendering?” Ask: “Is this re-render actually causing a performance issue?” Measure first. Optimize second. 💡 Final Thought React is built around predictable re-renders. Trying to eliminate them entirely often: - Adds complexity - Makes code harder to read - Introduces subtle bugs Clean code + correct mental model > aggressive optimization. Follow for more practical breakdowns. #ReactJS #JavaScript #FrontendDevelopment #SoftwareEngineering #WebDevelopment #ReactHooks
To view or add a comment, sign in
-
🚨 Stop using useEffect for everything in React. If you're still using useEffect to: • Derive state from props • Transform data for rendering • Handle simple computations You're probably writing more bugs than you think. 💡 React tip: 1️⃣ Derived data belongs in useMemo, not useEffect 2️⃣ Event-driven logic belongs in handlers 3️⃣ Effects are for synchronization with external systems The less useEffect you write, the more predictable your component becomes. Clean React code is about eliminating unnecessary effects. What’s one place you removed useEffect and simplified your code? #ReactJS #FrontendDevelopment #JavaScript #SoftwareEngineering #CleanCode
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