This week I built a small quiz app with React to push myself further and get hands on with concepts I hadn't fully explored yet. Here's how it went Here's what I built: • A quiz app with 15 questions fetched from a JSON server API • A 2-minute countdown timer that auto-ends the quiz when it hits zero • A live progress bar that updates as you move through questions • A point system where each question carries different points, tracked in real time • Answer reveal after selection with correct/wrong indicators • Two separate result screens for quiz completion and time running out What I learned building this: 1. useEffect: how to fetch data on mount, how cleanup functions work with timers, and why you cant pass an async function directly as the effect callback. 2. useReducer vs useState: I started with multiple useState calls for question index, options, score, and question number. It got messy fast. Switching to useReducer let me manage all of that through a single reducer with clear action types like "next" and "update". Way cleaner. 3. Timer logic in React: building a countdown sounds simple but it's tricky. You need setInterval inside useEffect, the cleanup function to clearInterval on every re-render, and handling the edge case when time hits zero. 4. Conditional rendering: handling different UI states (welcome → quiz → result → time over) all within one component taught me how to structure complex conditional renders. Bugs I fixed: Point system was broken because I wasnt using the value attribute on option buttons. The app had no way to know which option was selected. Added value={option} and scoring worked. Passed an async function directly as the useEffect callback. React expects it to return nothing or a cleanup function, not a Promise. Wrapped the fetch in an inner async function. Tried to read questions[0] on render before the API data loaded. State was still an empty array. Added a length check and showed a loading state instead. The app isnt perfect, but it works and every bug taught me something I wont forget. #React #JavaScript #FrontendDevelopment #WebDev
More Relevant Posts
-
The React Hook "Periodic Table": From Basics to Performance ⚛️ If you want to write clean, professional React code in 2025, you need more than just useState. While useState is the heart of your component, these 7 hooks form the complete toolkit for building scalable, high-performance apps. Here is the breakdown: 🌟 The Core Essentials 1️⃣ useState: The bread and butter. Manages local state (toggles, form inputs, counters). 2️⃣ useEffect: The "Swiss Army Knife." Handles side effects like API calls, subscriptions, and DOM updates. 3️⃣ useContext: The prop-drilling killer. Shares global data (themes, user auth) across your entire app without passing props manually. ⚡ The Performance Boosters 4️⃣ useMemo: Caches expensive calculations. Don't re-run that heavy data filtering unless your dependencies actually change! 5️⃣ useCallback: Memoizes functions. Perfect for preventing unnecessary re-renders in child components that rely on callback props. 🛠️ The Power Tools 6️⃣ useRef: The "Persistent Finger." Accesses DOM elements directly (like auto-focusing an input) or stores values that persist without triggering a re-render. 7️⃣ useReducer: The "Traffic Cop." Best for complex state logic where multiple sub-values change together. If your useState logic is getting messy, this is your solution. 💡 Pro-Tip : Keep an eye on React 19 hooks like useOptimistic (for instant UI updates) and useFormStatus (to simplify form loading states). The ecosystem is moving fast! Which hook do you find yourself reaching for the most lately? Is there a custom hook you’ve built that you now use in every project? 👇 #ReactJS #WebDevelopment #Frontend #CodingTips #Javascript #SoftwareEngineering #ReactHooks #WebDev2025
To view or add a comment, sign in
-
𝗠𝗮𝘀𝘁𝗲𝗿𝗶𝗻𝗴 𝗔𝘀𝘆𝗻𝗰/𝗔𝘄𝗮𝗶𝘁 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 JavaScript needs asynchronous code. This stops your app from freezing. Async/await makes this simple. Async/await uses Promises. Use the async keyword for functions. Use await to pause the function until the task finishes. Handle errors with try-catch blocks. Await throws errors if a Promise fails. Use try-catch to keep your app stable. Avoid await inside loops. It slows your code. Use Promise.all to run tasks at the same time. Best practices: - Use try-catch blocks. - Avoid await in loops. - Use Promise.all for multiple tasks. - Keep functions short. - Be consistent. Common mistakes: - Missing try-catch blocks. - Slow loops. - Ignoring Promise.all. - Mixing async with callbacks. Practice these steps. Your code will be cleaner. It will be easier to read. Source: https://lnkd.in/gGa2fKRN
To view or add a comment, sign in
-
Hey LinkedIn Family 👋 A JavaScript/React lesson that improved how I manage state: 🚀 Choosing the right tool matters: Context API vs Redux Toolkit vs Zustand Earlier, I thought one solution should handle everything. Now I choose based on project size and complexity. 1️⃣ Context API Best for: ✅ Theme ✅ Auth user info ✅ Language settings ✅ Small global state const ThemeContext = createContext(); Use when state is simple and doesn’t change frequently. 2️⃣ Redux Toolkit Best for: ✅ Large apps ✅ Complex business logic ✅ Async APIs ✅ Predictable state updates const store = configureStore({ reducer: { user: userReducer, }, }); Great for scalable production apps. 3️⃣ Zustand Best for: ✅ Medium apps ✅ Cleaner syntax ✅ Fast setup ✅ Less boilerplate const useStore = create((set) => ({ count: 0, inc: () => set((state) => ({ count: state.count + 1 })), })); Simple and powerful. My Rule of Thumb 👇 📌 Small app → Context 📌 Medium app → Zustand 📌 Large scalable app → Redux Toolkit Biggest Lesson: The best state management tool is not the most popular one… It’s the one that matches your project needs. What do you prefer using these days? 👇 #JavaScript #ReactJS #ReactNative #Redux #Zustand #WebDevelopment #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
⚡ next-route-xray (V1) https://lnkd.in/guUsANpr Fast routes insights for Next.js (𝗥𝘂𝘀𝘁 𝗰𝗼𝗿𝗲) Most Next.js apps feel fine… until suddenly one page becomes slow. 𝗔𝗻𝗱 𝘁𝗵𝗲𝗻 𝘆𝗼𝘂 𝘀𝘁𝗮𝗿𝘁 𝗱𝗶𝗴𝗴𝗶𝗻𝗴: bundle analyzer shows files, not routes Lighthouse tells you after build debugging becomes guesswork 𝗪𝗵𝗮𝘁’𝘀 𝗺𝗶𝘀𝘀𝗶𝗻𝗴 𝗶𝘀 𝘀𝗶𝗺𝗽𝗹𝗲: see problems early, before you build 🔍 What next-route-xray does It scans your project and shows: which routes are heavy which libraries are causing it which components are adding complexity 👉 all before you run build or deploy ⚙️ Why Rust is part of this Under the hood, this tool has to do a lot of work: read your imports build dependency graphs walk through component trees This gets heavy fast. JavaScript can handle it… but as your app grows, it slows down. So the plan is simple: Phase 1 → build fast in JS Next → move the heavy engine to Rust Rust helps with: faster analysis better performance on big projects more reliable results 🧾 Example 🔥 𝙷𝚒𝚐𝚑𝚎𝚜𝚝 𝚒𝚖𝚙𝚊𝚌𝚝 𝚛𝚘𝚞𝚝𝚎𝚜: 𝟷. /𝚊𝚍𝚖𝚒𝚗/𝚒𝚗𝚚𝚞𝚒𝚛𝚒𝚎𝚜 𝙸𝙽𝚂𝙸𝙶𝙷𝚃𝚂: - 𝚕𝚞𝚌𝚒𝚍𝚎-𝚛𝚎𝚊𝚌𝚝 → 𝚕𝚊𝚛𝚐𝚎 𝚏𝚘𝚘𝚝𝚙𝚛𝚒𝚗𝚝 - 𝚓𝚜𝚙𝚍𝚏 → 𝚕𝚊𝚛𝚐𝚎 𝚏𝚘𝚘𝚝𝚙𝚛𝚒𝚗𝚝 💡 𝙵𝚒𝚡: - 𝚞𝚜𝚎 𝚜𝚎𝚕𝚎𝚌𝚝𝚒𝚟𝚎 𝚒𝚖𝚙𝚘𝚛𝚝𝚜 - 𝚕𝚘𝚊𝚍 𝚑𝚎𝚊𝚟𝚢 𝚙𝚊𝚛𝚝𝚜 𝚘𝚗𝚕𝚢 𝚠𝚑𝚎𝚗 𝚗𝚎𝚎𝚍𝚎𝚍 🚧 𝗪𝗵𝗮𝘁’𝘀 𝗰𝗼𝗺𝗶𝗻𝗴 𝗻𝗲𝘅𝘁 Rust-powered engine (faster + stronger) better pattern detection (same issue across routes) CI support (catch issues in PRs) deeper component-level insights
To view or add a comment, sign in
-
🚀 New Project: Interactive Joke Generator in Next.js! I just built a dynamic random joke app exploring the power of Next.js Client Components and State Management. Technical Highlights: 🏗️ Architecture: Organised with Route Groups (projects) for a clean, scalable folder structure. ⚡ Data Fetching: Leveraged async/await and useEffect to pull live data from the Official Jokes API. 🧠 State Control: Implemented useState for a smooth Reveal/Hide punchline toggle and "Next Joke" functionality. 🎨 Styling: Fully responsive UI built with Tailwind CSS integrated via globals.css. Understanding the "use client" boundary and preventing unnecessary re-renders was a great deep dive into React performance! #NextJS #ReactJS #WebDev #TailwindCSS #Coding #Javascript
To view or add a comment, sign in
-
Stop fighting React Final Form re-initialization where the form suddenly resets and clears everything the user typed. In React, when a component re-renders, any object you create inside it gets a new "reference" or identity in memory. Since React Final Form uses a simple reference check for initialValues by default, these re-renders trick the form into thinking the data is brand new, triggering a full reset even if the values haven't changed. While using useMemo is a common fix to keep that reference stable, it can quickly make your code messy and harder to maintain as your data grows. A much simpler solution is to use the initialValuesEqual prop as shown in the snippet below. By using JSON.stringify, you tell the form to look at the actual data instead of the memory address. This keeps your form stable and protects the user's input, no matter how many times the parent component re-renders. This small change decouples your form from the component's render cycle. It ensures the form only resets when the data truly changes, making your app feel much more professional and reliable. #ReactJS #WebDevelopment #Frontend #ReactFinalForm #CodingTips
To view or add a comment, sign in
-
-
𝗪𝗵𝘆 𝗬𝗼𝘂𝗿 𝗝𝗮𝘃𝗮𝘀𝗰𝗿𝗶𝗽𝘁 𝗙𝗲𝗲𝗹𝘀 𝗦𝗹𝗼𝘄 𝗔𝗻𝗱 𝗛𝗼𝘄 𝗠𝗮𝘀𝘁𝗲𝗿𝗶𝗻𝗴 𝗔𝘀𝘆𝗻𝗰 𝗪𝗶𝗹𝗹 𝗙𝗶𝘅 𝗜𝘁 Is your app freezing? The real reason is async JavaScript handled poorly. JavaScript runs on one thread. It does one task at a time. Async tasks let it handle many things without stopping. Here are the async tools you must know: - Promises: Manage tasks that finish later. - async/await: Write async code that reads step by step. - try...catch: Always catch errors. - Promise.all(): Run independent tasks at the same time. - Avoid long tasks on the main thread. My friend had a slow app. He fixed the async code. Load times dropped. The app stayed the same. The async handling improved. Use async/await for clearer code today. Your app does not need less work. It needs to work smarter. What part of async is hardest for you? Promises? async/await? Multiple tasks? Source: https://lnkd.in/gghEGCR8
To view or add a comment, sign in
-
🚀 Built a Quiz Practice Web App using simple web tech + Vibe Coding I created a lightweight Quiz Taker application using: • HTML, CSS, JavaScript (frontend) • Google Apps Script (backend) • CSV-based question storage from Google Drive 🔧 Key Features: - Loads questions dynamically from CSV - Custom Apps Script API for data handling - Instant score + answer explanations - Clean and responsive UI - Voice Command Taker 💡 What stood out: You don’t always need complex frameworks. With the right approach, even simple tools can build practical and scalable applications. 🔗 Try it here: https://lnkd.in/gWfmNGSF #WebDevelopment #JavaScript #GoogleAppsScript #VibeCoding
To view or add a comment, sign in
-
-
🚀 Small Bug, Big Lesson in Full-Stack Development I recently worked on improving a web app by making the user experience smoother — instead of typing long zone names manually, users can now simply search or select from a dropdown list. But during this update, everything broke. The frontend stopped communicating properly with the backend, and the entire feature failed. After digging through the code, checking API responses, and debugging step-by-step, I finally found the issue… A simple variable mismatch: “zone” vs “zones” That tiny inconsistency was enough to break the connection between the frontend and backend API. 🔍 What I learned: - Consistency in naming is critical in full-stack development - Debugging is not about guessing, but tracing data flow carefully - Small changes can introduce unexpected system-wide issues 💡 Fixing this not only restored functionality but also reinforced how important attention to detail is when working across client and server. You can check out the project here: 👉 [https://lnkd.in/dCuCfCsv] #WebDevelopment #JavaScript #NodeJS #FullStackDeveloper #Debugging #SoftwareEngineering #LearningInPublic #Frontend #Backend #CodingJourney
To view or add a comment, sign in
-
Built a Todo App using HTML, CSS & JavaScript A simple yet functional app to manage daily tasks with features like add/delete, input validation, and dynamic updates using DOM. Learning by building 🚀 <!DOCTYPE html> <html> <body> <h3>Todo App</h3> <input type="text" id="t1"> <button onclick="add()">Add</button> <ul id="list"></ul> <script> function add() { var x = document.getElementById("t1").value; var li = document.createElement("li"); li.innerHTML = x + " <button onclick='this.parentElement.remove()'>Delete</button>"; document.getElementById("list").appendChild(li); } </script> </body> </html>
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
Great 👏🔥