Handling a single Promise is easy. Handling multiple Promises correctly is where things get interesting. In real-world apps, we often need to: • Wait for everything to complete • Pick the first successful result • React to the fastest response • Or simply collect all outcomes That’s exactly what Promise combinators solve. In my latest blog, I’ve explained: • Promise.all • Promise.any • Promise.race • Promise.allSettled Using a simple and relatable wedding planning analogy 💍 The goal was simple — make async logic feel intuitive, not intimidating. If you’ve ever been confused about these methods, this will help. Read here 👇 https://lnkd.in/gtcRWS5E Would love your feedback! #JavaScript #WebDevelopment #AsyncProgramming #Frontend
Master Promise Combinators in JavaScript
More Relevant Posts
-
🪝: Our app was slow. Users were complaining. Here's the 5 things that fixed it (and the 1 thing that almost made it worse). Performance optimisation is one of those things that sounds abstract until you have actual users complaining. Here's what I've done in real projects that actually moved the needle: 1. CODE SPLITTING with React.lazy() → Don't load the whole app on first visit → Lazy load routes and heavy components → Real impact: cut initial load time by ~40% on a large project 2. MEMOISATION — but only where it matters → React.memo() for components that receive the same props often → useMemo() for expensive calculations → useCallback() for functions passed as props → WARNING: Over-memoising adds overhead. Profile first, optimise second. 3. OPTIMISED RENDER CYCLES → Identify what's causing unnecessary re-renders (React DevTools Profiler is your best friend) → Move state as close to where it's used as possible → Avoid storing derived data in state — calculate it 4. IMAGE OPTIMISATION → Lazy load images below the fold → Use appropriate formats (WebP where possible) → Set explicit width/height to avoid layout shifts 5. BUNDLE ANALYSIS → Use webpack-bundle-analyzer or Vite's rollup-plugin-visualizer → You'll be shocked what's in your bundle sometimes The thing that almost made it worse? Premature memoisation everywhere. We wrapped every component in React.memo before profiling. It actually slowed things down. MEASURE. THEN OPTIMISE. What's your go-to performance trick? #ReactJS #PerformanceOptimisation #FrontendDev #JavaScript #WebPerformance #CodeSplitting #ReactHooks
To view or add a comment, sign in
-
I deleted 70% of useEffect calls in a production React app. Nothing broke actually it became faster. The real problem wasn't "too many effects" it was derived state computed inside effects instead of during render. Context: A dashboard with filters, sorting, and real-time updates. Each filter change triggered useEffect → setState → re-render → another useEffect classical chain reaction. What I did instead: Moved all derived data into useMemo + selector functions. Used event handlers for user actions (filters, sorting). Kept useEffect only for external sync (localStorage, analytics, WebSocket). Rule I now use: If you setState inside useEffect - stop. Ask can this be calculated during render? Result: 7 effects --> 2 effects Rerenders per filter change: from 4 --> 1 Bug: impossible (no more stale closure issues) The shift in thinking: React is not reactive like Vue or Svelte. it's declarative. State --> UI. Effects are escape hatches, not data flow tools Question for you: What is the most confusing useEffect bug you've ever debugged? #react #typeScript #frontendperformance
To view or add a comment, sign in
-
-
A small state change once caused a full UI lag in our app. Not because of heavy logic. Because of a re-render cascade. Here’s what was happening 👇 Problem: → Small interaction → noticeable lag → Entire UI felt slow Root cause: → State lifted too high → Parent re-render triggered entire subtree → Components not isolated What I did: → Moved state closer to usage → Split component tree into smaller boundaries → Reduced unnecessary parent updates Result: → Significant performance improvement → Faster interactions → Better user experience Insight: Performance issues are often not “heavy code”. They’re “wide impact”. Control the blast radius of a render. #ReactJS #Performance #Frontend #SoftwareEngineering #CaseStudy #Optimization #JavaScript #Engineering #WebDevelopment #ScalableSystems #FrontendDeveloper
To view or add a comment, sign in
-
💡 How would you design a real-time notifications system in a frontend app? Here’s a practical approach I like to follow. I separate communication into two layers: 🔹 REST APIs for CRUD operations 🔹 WebSockets for real-time updates On the frontend, I create a WebSocket service that: • Maintains the connection • Handles reconnection logic • Parses incoming messages To keep things scalable and decoupled, I use a pub/sub (event-based) system. Components subscribe to specific notification types, so updates flow efficiently without tight coupling. For state management, notifications live in a centralized store or data-fetching layer—ensuring consistency across the app. ⚡ Performance matters: • Batch updates when needed • Avoid unnecessary re-renders (memoization) • Limit rendered items (virtualization or pagination) And of course, don’t forget the edge cases: 🔸 Connection loss 🔸 Duplicate messages 🔸 Message ordering Clean architecture + resilience = a smooth real-time experience. How would you approach this? #FrontendDevelopment #WebDevelopment #SoftwareArchitecture #RealTimeSystems #WebSockets #JavaScript #ReactJS #SystemDesign #Programming #TechEngineering
To view or add a comment, sign in
-
-
Along with the search filter, I built a simple notes app. The idea was straightforward: type something → save it → keep it even after refresh. It mainly involved: • capturing user input • updating the UI dynamically • storing data in localStorage • retrieving it back on reload Nothing complex, but it tied together multiple concepts in a practical way. Seeing data persist made the whole flow feel closer to a real application. #javascript #webdevelopment #frontend
To view or add a comment, sign in
-
Nobody talks about this React performance trap — and it bit me hard in production. I was using useContext to manage auth + theme + cart state in a mid-size app. Only a few components actually used the cart state. But every time the cart updated — every single component consuming the context re-rendered. Even the ones that only needed the user's name. Here's why: React's Context API re-renders all consumers whenever the context value reference changes — regardless of which slice of state they actually use. There are workarounds with Context: → Split into multiple contexts (AuthContext, CartContext, ThemeContext separately) → Wrap consumers in React.memo() → Use useMemo to stabilize the context value But honestly? All of these feel like duct tape. This is exactly where Zustand and Redux Toolkit shine. Both let you subscribe to only the slice of state you need. A component using useSelector(state => state.user.name) will only re-render when that specific value changes — not when the cart updates, not when the theme toggles. ZUSTAND Minimal boilerplate, great for small-to-mid apps. Selector-based subscriptions built in. REDUX TOOLKIT Structured, scalable. useSelector memoizes out of the box with Reselect. The lesson I took away: useContext is great for low-frequency, global state (auth, theme, locale). The moment you have state that changes often and is consumed by many components — reach for a proper state manager. Performance issues in React are rarely obvious until they're in production. Knowing why re-renders happen matters more than memorizing which hook to use. Have you run into this? Would love to hear how you solved it — Context splitting, Zustand, RTK, or something else entirely? #ReactJS #JavaScript #WebDevelopment #Frontend #Zustand #Redux
To view or add a comment, sign in
-
🚀 **Built a Live Character Counter App** Recently, I worked on a small project — a **Live Character Counter App** — to strengthen my JavaScript fundamentals. Through this project, I practiced: * String methods like `trim()` and `replace()` * Array method `filter()` for accurate word counting * Conditional logic * DOM manipulation * Event handling (especially `input` events) The app tracks: ✔ Character count ✔ Word count ✔ Remaining characters ✔ Live input feedback This project helped me understand how to handle edge cases like extra spaces and improve user experience with real-time updates. 💡 Small projects like this build a strong foundation for real-world applications. 🔗Live preview:- https://lnkd.in/gGVaUv9G If you have any suggestions or ideas for improvement, I’d really appreciate your feedback in the comments 🙌 #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
Most React apps don’t struggle because of complex logic. They struggle because of small things we overlook. I’ve run into these patterns multiple times, and fixing them makes a huge difference. 1️⃣ Infinite scroll lag Scrolling feels heavy because listeners fire too often. 🔹 Use IntersectionObserver to detect when the last item is visible, much smoother. 2️⃣ Too many API calls Quick tab switches or clicks = multiple requests firing. 🔹 Use AbortController to cancel previous calls, only the latest one runs. 3️⃣ Slow image loading Loading everything upfront kills performance. 🔹 Use loading "lazy" (+ observer if needed) to load images only when needed. 4️⃣ State updates after unmount 🔹Clean up requests inside useEffect using AbortController. 5️⃣ Unnecessary background work App keeps fetching data even when the tab isn’t active. 🔹 Use Page Visibility API to pause/resume work. 6️⃣ Race conditions in search Old results overriding new ones = confusing UX. 🔹 Cancel previous requests before firing new ones. #ReactJS #FrontendDevelopment #WebPerformance #JavaScript #SoftwareEngineering #CodingInterview #CareerGrowth #InterviewPrep
To view or add a comment, sign in
-
You’re Re-Rendering Your Whole App Without Realizing It 🤯 React Context is a brilliant tool for dependency injection. It is terrible for rapidly changing state. Here is the trap most mid-level developers fall into: The "God Context." The Trap: The Re-Render Nuke ☢️ You need the user profile, theme preferences, and shopping cart available everywhere. You wrap your entire app in a giant <GlobalContext.Provider>. A user clicks "Add to Cart." The cart state updates. What happens next? Every single component that consumes that context is forced to re-render. Even your navigation bar that only needed to know if it was in "dark mode". You just nuked your own DOM. The app feels sluggish. The Fix: Atomic State (Zustand / Jotai) ⚛️ Modern frontend architecture has moved away from top-down context for dynamic state. We use atomic state managers like Zustand. Instead of a massive global object, components subscribe only to the specific slice of state they care about. Update the cart? Only the CartBadge component re-renders. The rest of your DOM stays completely frozen. 0ms wasted CPU time. The Senior Takeaway: Use React Context for static, low-frequency updates (Themes, Auth Tokens). Use Zustand/Redux for dynamic, high-frequency state. Are you still stuffing everything into a global Context, or have you moved to atomic state? 👇 #ReactJS #FrontendEngineering #WebDevelopment #SoftwareArchitecture #SystemDesign #PerformanceOptimization #FullStack
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