Day 9: Lists & Keys in React In real-world apps, we often need to display lists of data like products, users, or posts. React makes this easy using Lists & Keys. 📌 What are Lists in React? Lists allow us to render multiple elements dynamically using JavaScript methods like map(). 📌 Example: Rendering a List function App() { const fruits = ["Apple", "Banana", "Mango"]; return ( <ul> {fruits.map((fruit) => ( <li>{fruit}</li> ))} </ul> ); } This will display all items in the array as a list. 📌 What are Keys in React? Keys are special attributes used to uniquely identify elements in a list. They help React track changes efficiently and improve performance. 📌 Example with Keys function App() { const fruits = ["Apple", "Banana", "Mango"]; return ( <ul> {fruits.map((fruit, index) => ( <li key={index}>{fruit}</li> ))} </ul> ); } 📌 Why Keys are Important Without keys, React cannot properly identify which items changed, added, or removed. Benefits: ✅ Better performance ✅ Efficient updates ✅ Avoid UI bugs 📌 Best Practice ❌ Avoid using index as key (if list can change) ✅ Use a unique ID whenever possible #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #CodingJourney #LearnInPublic
React Lists & Keys: Efficient Rendering and Performance
More Relevant Posts
-
🚀 Is Your React App Slowing Down? It Might Be Your Bundle Size One silent performance killer in React apps is a large JavaScript bundle. The bigger your bundle, the longer it takes to: Load ⏳ Parse 🧠 Execute ⚙️ And users? They feel it immediately. 💡 The Fix: Code Splitting + Lazy Loading Instead of shipping your entire app at once… 👉 Load only what the user needs, when they need it. 🧩 Code Splitting Break your app into smaller chunks. Each route or feature becomes its own bundle instead of one massive file. ⚡ Lazy Loading with React.lazy Load components on demand: const CityList = React.lazy(() => import("./CityList")); 🎯 Use with Suspense <Suspense fallback={<Spinner />}> <CityList /> </Suspense> 👉 Now your component loads only when needed, not upfront. 🛣️ Route-Based Splitting (Best Practice) Perfect for pages: const Home = React.lazy(() => import("./pages/Home")); const Product = React.lazy(() => import("./pages/Product")); Users only download the page they visit 👇 Not your entire app. 🔥 Why This Matters ✅ Faster initial load time ✅ Better performance on low-end devices ✅ Improved user experience ✅ Lower data usage 🧠 Pro Tip Don’t lazy load everything. 👉 Lazy load: Pages Heavy components (charts, maps, editors) 👉 Don’t lazy load: Small reusable components (buttons, inputs) 🧩 Final Thought Performance isn’t just about writing code… It’s about when your code loads. Ship less. Load smarter. Scale better. #React #WebPerformance #Frontend #JavaScript #CodeSplitting #LazyLoading #SoftwareEngineering
To view or add a comment, sign in
-
🗓️ Day 6 of 30 — Dynamic Routes & Params in Next.js Most real apps don't have fixed pages only. You need pages like: /blog/how-to-learn-nextjs /product/123 /user/zeeshan That's where Dynamic Routes come in. 📁 How it works in App Router: Instead of a fixed filename, you wrap it in square brackets: app/ └── blog/ └── [slug]/ └── page.tsx Now /blog/anything will match this route. 🎯 📦 Accessing the param: export default function BlogPost({ params, }: { params: { slug: string }; }) { return <h1>Post: {params.slug}</h1>; } Next.js automatically injects params — no extra setup needed. 🔁 What about multiple dynamic segments? app/shop/[category]/[productId]/page.tsx // params = { category: "shoes", productId: "42" } You can nest as many as you need. ⚡ Bonus — generateStaticParams: Want to pre-render dynamic pages at build time (for performance)? export async function generateStaticParams() { return [ { slug: "nextjs-basics" }, { slug: "dynamic-routes" }, ]; } This tells Next.js: "Hey, build these pages ahead of time." No waiting. Blazing fast. 🔥 💡 Key Takeaway: Dynamic routes let you build flexible, scalable pages without hardcoding every URL. One file → infinite pages. That's the power of Next.js. 📌 Follow for Day 7 tomorrow! What topic should I cover next? Drop it in the comments 👇 #NextJS #React #WebDevelopment #30DaysOfNextJS #Frontend #JavaScript #LearningInPublic
To view or add a comment, sign in
-
Day 3 - 250+ countries. One React app. Zero API keys needed. 🚀TechFromZero Series - ReactFromZero This isn't a Hello World. It's a real single-page app with routing: 📐 Search → REST Countries API → Country Cards → Detail Page 🌐 Try it live: https://lnkd.in/d9faDYY2 🔗 The full code (with step-by-step commits you can follow): https://lnkd.in/dBpQXpZm If anyone has a idea, improvement or recommendation please try to fork the repo and submit a pull request, Everyone is welcome to do so. 🧱 What I built (step by step): 1️⃣ React app with header and folder structure 2️⃣ API client — REST Countries fetch helpers 3️⃣ CountryCard — reusable card with flag + info 4️⃣ CountryList — responsive grid with live data 5️⃣ SearchBar — instant filtering as you type 6️⃣ RegionFilter — dropdown by continent 7️⃣ CountryDetail — full detail page with borders 8️⃣ Styling — sticky header, animations 9️⃣ README — complete guide 💡 Every file has detailed comments explaining WHY, not just what. Written for any beginner who wants to learn React by reading real code — with full clarity on each step. 👉 If you're a beginner learning React, clone it and read the commits one by one. Each commit = one concept. Each file = one lesson. Built from scratch, so nothing is hidden. 🔥 This is Day 3 of a 50-day series. A new technology every day. Follow along! 🌐 See all days: https://lnkd.in/dhDN6Z3F #TechFromZero #Day3 #React #JavaScript #Frontend #API #LearnByDoing #OpenSource #BeginnerGuide #100DaysOfCode #CodingFromScratch
To view or add a comment, sign in
-
-
🚀 Your React app might be re-rendering more than you think… and hurting performance. While working on large-scale applications, I kept running into unnecessary re-renders that slowed things down. Here’s a simple fix that made a big difference 👇 🔻 Without Optimization Every time the parent re-renders, the child re-renders too ❌ const Child = ({ onClick }) => { console.log("Child re-rendered"); return <button onClick={onClick}>Click Me</button>; }; function Parent() { const handleClick = () => { console.log("Clicked"); }; return <Child onClick={handleClick} />; } 🔻 Optimized Version import React, { useCallback } from "react"; const Child = React.memo(({ onClick }) => { console.log("Child re-rendered"); return <button onClick={onClick}>Click Me</button>; }); function Parent() { const handleClick = useCallback(() => { console.log("Clicked"); }, []); return <Child onClick={handleClick} />; } ✅ Child now re-renders only when props actually change ✅ Prevents unnecessary updates ✅ Improves performance in large component trees 💡 Key Insight: In React, functions are re-created on every render → which can trigger unwanted re-renders. Have you faced this issue in your projects? How do you handle performance optimization in React? 👇 hashtag #ReactJS #FrontendDevelopment #JavaScript #PerformanceOptimization #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
I reduced my React app’s bundle size by 60% here’s how I did it. At some point, every React app starts facing performance issues. One major reason is the bundle size. It quietly slows down your app, and many teams don’t notice it early. After doing a proper performance check, I reduced the bundle size from 4.2MB to 1.6MB. At the same time, the page load speed (LCP) improved from 6.8 seconds to 1.9 seconds. Here are the key things that helped: 1. I used a bundle analyzer to see which files and libraries were making the app heavy. This gave me a clear direction on what to fix. 2. I applied tree shaking by using proper imports. This removed a lot of unused code from the final build. 3. I added code splitting using React.lazy() and Suspense, so heavy components like charts and modals load only when needed. 4. I enabled Gzip and Brotli compression on the server, which reduced file size during transfer without changing any code. 5. I reviewed dependencies and replaced heavy libraries like moment.js and lodash with lighter options and native JavaScript. The result was very clear — faster loading, better performance scores, and a smoother user experience. If you’re working with React, optimizing bundle size is not optional. It directly impacts how fast and smooth your app feels to users. For more insightful content checkout below: 🟦 𝑳𝒊𝒏𝒌𝒆𝒅𝑰𝒏 - https://lnkd.in/dwi3tV83 ⬛ 𝑮𝒊𝒕𝑯𝒖𝒃 - https://lnkd.in/dkW958Tj 🟥 𝒀𝒐𝒖𝑻𝒖𝒃𝒆 - https://lnkd.in/dDig2j75 or Priya Frontend Vlogz 🔷 𝐓𝐰𝐢𝐭𝐭𝐞𝐫 - https://lnkd.in/dyfEuJNt #frontend #javascript #react #reactjs #html #css #typescript #es6 #interviewquestions #interview #interviewpreparation
To view or add a comment, sign in
-
-
🚀 I just built and deployed my first production-ready React app — a Smart Expense Tracker! Here's what it does: ✅ Real-time budget alerts that warn you at 80% and 100% of your monthly budget ✅ Interactive Pie & Bar charts to visualize spending by category ✅ Category filtering to manage expenses easily ✅ Data persistence using localStorage — your expenses survive even after closing the browser --- 🔧 The hardest problem I faced: A classic race condition with localStorage. Every time the app loaded, expenses were being saved as an empty array BEFORE the saved data could be loaded from localStorage. So data was getting wiped on every refresh. The fix? A simple but powerful condition: Only save to localStorage when expenses.length > 0 This ensured we never overwrite real data with an empty state during the initial render. --- 💡 My favourite part of the whole build? Two things — localStorage persistence (because it makes the app feel genuinely real) and the data visualizations using Recharts (because seeing your spending broken down in a pie chart hits different 😅) --- 🛠️ Tech Stack: React • Vite • Tailwind CSS • Recharts • Framer Motion • localStorage • Vercel 🔗 Live demo: https://lnkd.in/gWf6H395 Would love your feedback — what feature should I build next? #React #JavaScript #Frontend #WebDevelopment #ReactJS #buildinpublic
To view or add a comment, sign in
-
Recently, I worked on a project where users noticed slow loading in some parts of the app. After much research i realized unnecessary state updates and re-renders were causing the problem. I reworked the data flow and optimized state logic, and the app became much faster and more responsive. This reminded me how small architectural decisions can have a huge impact. Here’s a simple illustration: // Before: child re-renders every time parent updates const Parent = () => { const [count, setCount] = useState(0); return ( <> <button onClick={() => setCount(count + 1)}>Increment</button> <ExpensiveChild /> </> ); }; // After: memoized child prevents unnecessary re-renders const ExpensiveChild = React.memo(() => { console.log('ExpensiveChild rendered'); return <div>Expensive Child</div>; }); #ReactJS #NextJS #FrontendDevelopment #WebPerformance #ReactOptimization #JavaScript #WebDevelopment #CodingTips
To view or add a comment, sign in
-
🚀 Code Splitting in React — Best Practices & Why It Matters Ever noticed your React app taking time to load? 🤔 That’s often because everything loads at once… 👉 This is where Code Splitting comes in ⚡ 🧩 What is Code Splitting? 👉 Break your app into smaller chunks 👉 Load only what’s needed Instead of loading the entire app at once, React loads components on demand 💡 ⚙️ Basic Example js import React, { Suspense, lazy } from "react"; const Dashboard = lazy(() => import("./Dashboard")); export default function App() { return ( <Suspense fallback={<p>Loading...</p>}> <Dashboard /> </Suspense> ); } 🧠 Best Practices ✔ Use `React.lazy()` for components ✔ Wrap with `Suspense` for fallback UI ✔ Split routes (page-level splitting) ✔ Avoid over-splitting (too many small chunks) ✔ Combine with dynamic imports ⚡ Why It Matters? ✔ Faster initial load time ✔ Better performance ✔ Improved user experience ✔ Reduced bundle size 🔥 Real-world Usage 👉 Large dashboards 👉 E-commerce apps 👉 Admin panels 👉 Feature-based modules 🧠 Simple Way to Understand • Without Code Splitting → Load everything 🚫 • With Code Splitting → Load only needed parts ✅ 💬 Are you using code splitting in your project or still loading everything at once? --- #React #Frontend #WebPerformance #JavaScript #WebDevelopment #Coding #SoftwareEngineering
To view or add a comment, sign in
-
-
Built something practical and actually useful 💻✨ — introducing my Invoice Builder Web App! Creating invoices shouldn’t be complicated, so I designed this app to make it fast, clean, and user-friendly — from adding client details to generating professional invoices in just a few clicks. 🛠️ Tech Stack Used: React Native, Express.js, JavaScript, MongoDB This project helped me strengthen my full-stack development skills, improve UI/UX thinking, and work with real-world data handling and backend integration. Sharing a quick demo video here 👇 Would love your feedback and suggestions! #WebDevelopment #FullStackDeveloper #ReactNative #ExpressJS #MongoDB #JavaScript #ProjectShowcase #BuildInPublic
To view or add a comment, sign in
-
😩 I used to HATE when my entire website just... went white. No error. No message. Just a blank screen staring back at me. I'd spend hours trying to figure out what went wrong — refreshing, console-diving, questioning my life choices. 😅 The worst part? One small bug was taking down the ENTIRE app. Not just one section. Everything. Then I discovered Error Boundaries in React — and it changed how I build apps forever. 🙌 Here's what it does in simple terms: Instead of letting one broken component crash your whole UI, Error Boundary catches the error and shows a friendly fallback message — while keeping the rest of your app running perfectly. ✅ <ErrorBoundary fallback={<p>Oops! Something went wrong here.</p>}> <MyUnpredictableComponent /> </ErrorBoundary> Now instead of a white screen of death 💀 — my users see a clean message, and everything else on the page still works. I now wrap Error Boundaries around: 🔹 Third-party components I don't fully control 🔹 Data-heavy sections that depend on APIs 🔹 Any experimental features in production 🔹 Dashboard widgets that load independently It's one of those things nobody really talks about — but once you use it, you wonder how you ever shipped without it. If you've ever stared at a blank white screen wondering what went wrong — this is your sign to add Error Boundaries to your project TODAY. 🚀 Have you used Error Boundaries before? Or did you also suffer the white screen curse? 😂 Tell me in the comments! #ReactJS #WebDevelopment #Frontend #JavaScript #ErrorBoundary #SoftwareEngineering #React #
To view or add a comment, sign in
Explore related topics
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