Thursday – React Tip ⚛️ Not every state belongs in React state. One common mistake I see: Using useState for values that don’t affect rendering. Example: const [timerId, setTimerId] = useState(null) But if the value doesn’t impact UI, storing it in state causes unnecessary re-renders. Better option: Use useRef. const timerRef = useRef(null) Why this works: useRef stores values that persist between renders without triggering re-renders. Good use cases: • Storing timers • Accessing DOM elements • Keeping mutable values • Tracking previous values Think of it like this: useState → affects UI useRef → internal value storage Small decisions like this help keep React apps efficient. React performance often comes down to choosing the right hook for the job. #ReactJS #FrontendDevelopment #ReactTips #WebDevelopment #LearningInPublic
React State vs Ref: Choosing the Right Hook
More Relevant Posts
-
Most React performance problems I have encountered are not caused by slow components; they are caused by unnecessary re-renders that nobody noticed during development. It is easy to ship a feature that works perfectly in isolation and then discover, six months later, that it is quietly re-rendering on every keystroke in a parent form, or recalculating a derived value on every state update because nobody reached for useMemo at the right moment. A few things that have genuinely helped on client projects: First, treat your component tree as a data-flow diagram, not just a UI structure. Knowing exactly where state lives, and why, prevents you from lifting state higher than it needs to go. Second, in Next.js App Router projects, be deliberate about the boundary between Server and Client Components. Keeping data-fetching on the server and passing minimal props to Client Components does more for performance than any client-side optimisation trick. Third, profile before you optimise. React DevTools Profiler will often surprise you; the slow part is rarely where you assumed it was. The real issue is that performance debt accumulates silently. It does not break tests or trigger errors; it just gradually degrades the experience until users notice before you do. What is the most effective performance improvement you have made in a React or Next.js project recently? I would be curious to hear what the root cause turned out to be. #ReactJS #NextJS #FrontendDevelopment #WebPerformance
To view or add a comment, sign in
-
🚀 Ever wondered how React updates the UI so fast without reloading everything? That magic is called Reconciliation. 💡 React doesn’t blindly re-render the entire DOM. Instead, it follows a smart process: 🔹 When state or props change → React creates a new Virtual DOM 🔹 It compares it with the previous Virtual DOM (Diffing) 🔹 Identifies exactly what changed (Add / Update / Remove) 🔹 Applies only the minimal required changes to the real DOM 👉 Example: If only a list item changes, React updates just that item — not the whole list. ⚡ Why this is powerful: • Faster UI updates • Better performance (O(n) diffing) • Efficient DOM manipulation • Smart reuse of unchanged elements • Keys help React track list items correctly 🔥 In short: React updates only what’s necessary, not everything. That’s why React apps feel smooth and blazing fast. #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #React #Performance #VirtualDOM
To view or add a comment, sign in
-
-
🚀 Ever wondered how React updates the UI so fast without reloading everything? That magic is called Reconciliation. 💡 React doesn’t blindly re-render the entire DOM. Instead, it follows a smart process: 🔹 When state or props change → React creates a new Virtual DOM 🔹 It compares it with the previous Virtual DOM (Diffing) 🔹 Identifies exactly what changed (Add / Update / Remove) 🔹 Applies only the minimal required changes to the real DOM 👉 Example: If only a list item changes, React updates just that item — not the whole list. ⚡ Why this is powerful: • Faster UI updates • Better performance (O(n) diffing) • Efficient DOM manipulation • Smart reuse of unchanged elements • Keys help React track list items correctly 🔥 In short: React updates only what’s necessary, not everything. That’s why React apps feel smooth and blazing fast. #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #React #Performance #VirtualDOM
To view or add a comment, sign in
-
-
🌤️ Just launched my Weather App built with React! This project was a great way to dive deeper into React fundamentals while building something practical. The app lets users search for real-time weather data by city and displays: 🌡️ Current Temperature 💧 Humidity Levels 🔼 Max & 🔽 Min Temperature 🌬️ Feels Like Temperature Key learnings from this build: ✅ Component-based architecture ✅ State management with React hooks ✅ API integration & data fetching ✅ Responsive UI design Shoutout to the React community for the amazing resources! Open to feedback and suggestions for improvements. 🚀 #ReactJS #WebDevelopment #JavaScript #FrontendDevelopment #ProjectShowcase #LearningJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Just launched: react-state-vitals A zero-config memory & render monitor for React apps. While working on production apps, I kept asking: 👉 Why is this component re-rendering so much? 👉 Which store is growing in memory? 👉 Where is my performance actually going? So I built a tool to make this visible — instantly. 🧠 react-state-vitals gives you a live floating panel in development: • 📊 Store size tracking (Zustand, Context, React Query) • 🔁 Re-render counts per component • 🧬 JS heap usage insights • ⚡ Zero setup — just install and see Think of it as: 👉 “Vitals for your React state & memory” 📦 Try it here: https://lnkd.in/gU692hyT 🔥 Next I’m planning: • DevTools-like overlay • Identify memory-heavy components in real time • Visual performance timeline Would love feedback from fellow devs 🙌 What would you want this to track next? #React #JavaScript #Frontend #WebPerformance #OpenSource #NextJS #Zustand
To view or add a comment, sign in
-
Today I explored React Router and key concepts behind Single Page Applications (SPA). 🔹 SPA – Loads a single HTML page and dynamically updates content without full page reloads. Example: Facebook, Gmail. 🔹 React SPA – Component-based SPA built with React. Each UI part is a reusable component. 🔹 Routing – Controls which component shows based on the URL, keeping navigation fast. 🔹 Nested Routing & Outlet – Parent routes can have child routes, and Outlet decides where the child renders. Example: Dashboard → Profile / Settings. 🔹 Link & NavLink – Link navigates without reload; NavLink highlights active routes. 🔹 Loader & useLoaderData – Fetch data before route renders and access it in the component easily. 🔹 Params & Dynamic Routes – Capture dynamic URL values with: id and useParams(). Example: /user/5 → id = 5. 🔹 useNavigate – Programmatically navigate between routes. Example: Redirect after form submission. Understanding these makes building scalable and smooth React apps much easier! #React #SPA #Frontend #WebDevelopment #JavaScript
To view or add a comment, sign in
-
-
Today everything started to feel… more real. React Masterclass (Day 5). I began with: • Sharing state between components • Passing functions as props • Understanding how React handles state updates But instead of stopping there, I asked: How would this actually work in a real app? 💰 So I built a Budget Tracker: • Set initial balance • Add expenses that reduce it in real-time • Dynamic UI based on current state • Data persisted using localStorage • Clean updates using functional state 💡 Key concepts that clicked: • Lazy initialization (run logic only once) • Functional updates (state based on previous state) • Derived values (calculating remaining balance) Small concepts → Real product thinking. #React #Frontend #WebDevelopment #LearningInPublic #JavaScript
To view or add a comment, sign in
-
Most teams ship slow apps because they optimize for developer experience first and user experience second. I get it. DX matters. But here's the thing — your users don't care how elegant your component tree is. They care that your page loads in under 2 seconds on a 4G connection. At my company, we made one architectural decision that cut our bundle size by 60%: we stopped shipping React to pages that don't need interactivity. Astro + Preact islands. That's it. The homepage? Static HTML with zero client-side JS. The dashboard? Full React with SSR through Next.js. The 3D product viewer? A single Preact island wrapping Three.js, lazy-loaded on scroll. Not every page deserves a 200KB runtime. As a founder, I've learned this the hard way — performance isn't a feature you bolt on later. It's an architectural decision you make on day one. Every millisecond of load time is conversion rate. Every unnecessary kilobyte is a user who bounced before your hero section rendered. Ship less JavaScript. Measure everything. Question every dependency you import. Your Lighthouse score is a business metric. Treat it like one. 🔥 #WebPerf #NextJS #SoftwareArchitecture #Astro #React
To view or add a comment, sign in
-
🧠 Part 3 of 10: Duplicated state is one of the fastest ways to make a React app feel unstable. Everything looks fine at first. Then one value updates. The other one doesn’t. Now the UI technically works, but nobody fully trusts it. That’s the part people don’t say enough: a lot of frontend bugs are really trust issues. The UI says one thing. The data says another. Now the team starts building around confusion. Whenever I can, I try to keep state close to a single source of truth. It makes code easier to reason about. And future changes get a lot less annoying. What bug have you traced back to duplicated state? #React #ReactJS #FrontendEngineering #StateManagement #JavaScript #UIEngineering #WebDevelopment
To view or add a comment, sign in
-
In large React applications, unnecessary re-renders can significantly impact performance and user experience. One effective technique to address this issue is using React.memo. React.memo prevents a component from re-rendering if its props have not changed. This is particularly beneficial when dealing with lists, product cards, dashboards, and extensive component trees. Example: const ProductCard = React.memo(({ product }) => { return <div>{product.name}</div>; }); Benefits of using React.memo include: - Improved performance - Reduced unnecessary renders - A more responsive UI in large applications Small optimizations like this can make a substantial difference in scalable React applications. #reactJs #webDevelopment #FrontendDevelopment #JavaScript
To view or add a comment, sign in
More from this author
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