🧠 Deep Dive: Why useSyncExternalStore matters (even if you never use it directly) When React 18 introduced concurrent rendering, one subtle problem appeared: How can React safely read from an external store (like Redux, Zustand, or a custom event emitter) without tearing — where your UI shows inconsistent data between renders? That’s why React introduced useSyncExternalStore. It ensures React always reads a consistent snapshot of external state — even during concurrent updates. Here’s a minimal example 👇 import { useSyncExternalStore } from 'react'; const store = { value: 0, listeners: new Set(), subscribe: (l) => { store.listeners.add(l); return () => store.listeners.delete(l); }, getSnapshot: () => store.value, setValue: (v) => { store.value = v; store.listeners.forEach(l => l()); } }; function Counter() { const value = useSyncExternalStore(store.subscribe, store.getSnapshot); return <button onClick={() => store.setValue(value + 1)}>{value}</button>; } This tiny hook keeps React and your store in perfect sync — with no tearing, no stale data, and full concurrency safety. It’s also what modern state libraries like Zustand and Redux Toolkit use under the hood. Understanding this helps you design custom stores that play nicely with React’s concurrent architecture — a step closer to truly React-native data flow. #React #JavaScript #Frontend #WebDevelopment #ReactJS #Performance #useSyncExternalStore #ConcurrentRendering #StateManagement #CleanCode #SoftwareEngineering #React18
How useSyncExternalStore prevents React data tearing
More Relevant Posts
-
#Redux isn’t the problem — how we use it is. I’ve seen this happen more than once in large React applications: developers #store every product list, catalog, and #API response directly in Redux… and suddenly the Redux #DevTools crash, and performance starts to drop . #What’s really going on Redux is incredible for application logic — filters, authentication, user preferences, etc. But it’s not designed to hold massive API payloads like entire product catalogs, inventory data, or analytics results. Every time a big payload is #dispatched, Redux has to #serialize it and keep it in history for time-travel debugging — and that quickly leads to slow renders and memory issues. #Modern Approach (2025) The best architecture I’ve seen in production platforms uses a hybrid model: . Redux (or Redux Toolkit) → Global app logic, filters, cart, user session, theme. . Zustand → UI state or heavy local data (product listings, cached search results, modals). . React Query → Handles API calls, caching, and background refetch automatically. Each tool has a clear purpose together they create a clean, scalable, and performant setup. #Why This Works Redux stays lightweight and fast. Zustand handles large, transient UI data without serialization overhead. React Query keeps API data fresh with smart caching. #Real Impact After refactoring projects like this: . Redux state dropped from 50 MB → under 1 MB . DevTools stayed stable . UI interactions became instant . Bundle impact: almost +15 kb . Developer productivity: way up #Takeaway Don’t fear adding small, purpose-built state tools. #Redux = global logic. #React Query = API cache. #Zustand = UI-level performance. When combined correctly, your bundle stays lean and your UI feels instant. #React #Redux #ReactQuery #Zustand #Frontend #WebDevelopment #SoftwareArchitecture #ReactJS #CleanCode #SeniorDeveloper
To view or add a comment, sign in
-
React architecture changed more in 18 months than in the previous 8 years. Here’s what actually works at scale in 2025 (learned the hard way): Adopt (server-first by default) • Server Components for data + heavy libs; push ‘use client’ to the leaves • TanStack Query for server state; Zustand or RTK for client/UI state • Three layers: Presentation (pure UI) → Application (hooks + pure funcs) → Services (IO) • Next.js 15 patterns: nested layouts, Suspense streaming, Server Actions • TypeScript everywhere, Tailwind (optionally shadcn/ui) for sane velocity Avoid (these collapse under growth) • Business logic inside components/hooks (test-hostile, not reusable) • God Context that re-renders the world on every change • Overusing effects for data fetching/mutations that belong on the server • Premature folder complexity before you hit real pain Principles that keep teams fast • If it doesn’t need state/effects/DOM, make it a pure function (DI for testability) • Feature-based folders past ~50 components; clear ownership boundaries • Caching is explicit; measure bundle size + CWV, not vibes Testing that actually pays off • 60–70% unit tests (pure funcs) • 20–30% integration (RTL) • 5–10% E2E (Playwright) on revenue-critical flows Result: smaller bundles, faster first paint via streaming, simpler tests, and code you can move between web and mobile without rewrites. #ReactJS #Nextjs #ServerComponents #TypeScript #WebDevelopment
To view or add a comment, sign in
-
𝗪𝗮𝗻𝘁 𝘁𝗼 𝗳𝗲𝘁𝗰𝗵 𝗱𝗮𝘁𝗮 𝘄𝗶𝘁𝗵𝗼𝘂𝘁 𝗯𝗹𝗼𝗰𝗸𝗶𝗻𝗴 𝘆𝗼𝘂𝗿 𝗨𝗜? 𝗧𝗿𝘆 𝗥𝗲𝗮𝗰𝘁 𝗦𝘂𝘀𝗽𝗲𝗻𝘀𝗲! Suspense lets you "wait" for async operations (like data fetching) without blocking the entire UI. No more loading spinners that freeze your app! How it works: → Wrap your async component with 𝗥𝗲𝗮𝗰𝘁.𝗦𝘂𝘀𝗽𝗲𝗻𝘀𝗲 → Use a "fallback" component (e.g., a spinner or skeleton screen) while data is loading → Once data is ready, React automatically swaps in the fully loaded component Benefits: • Improved user experience—only the relevant part of the UI waits for data • Cleaner code—no more manual loading states or conditional rendering • Seamless integration with React Query, SWR, or other data-fetching libraries Example: ``` <Suspense fallback={<Spinner />}> <AsyncComponent /> </Suspense> ``` Tip: Combine Suspense with 𝗥𝗲𝗮𝗰𝘁.𝗹𝗮𝘇𝘆 for even better performance. Load components only when they’re needed! 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀: • 𝗥𝗲𝗮𝗰𝘁 𝗱𝗼𝗰𝘀: https://lnkd.in/dUpifpQG • 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗮𝗹 𝘁𝘂𝘁𝗼𝗿𝗶𝗮𝗹𝘀 𝗼𝗻 𝗦𝘂𝘀𝗽𝗲𝗻𝘀𝗲 + 𝗱𝗮𝘁𝗮 𝗳𝗲𝘁𝗰𝗵𝗶𝗻𝗴 #ReactJS #Suspense #DataFetching #WebDevelopment #JavaScript #Frontend #ReactDev
To view or add a comment, sign in
-
React components that break at 50k users usually share the same fatal flaw. They render everything, everywhere, all at once. Last month I refactored Rankue's dashboard components to handle 100k+ concurrent users. The architecture changes weren't what you'd expect. Instead of complex state managers, I focused on three core principles: 1. Lazy boundaries everywhere Components load only when viewport enters. Cut initial bundle by 73%. 2. Memoization at data level Memo expensive calculations, not entire components. React.memo on every component kills performance. 3. Virtual scrolling for lists DOM nodes cap at 50 visible items regardless of data size. Memory usage stays flat. The result? Page load dropped from 4.2s to 0.8s. Memory consumption down 60%. Most developers optimize components. I optimize data flow. The biggest performance gains come from rendering less, not rendering faster. What's your approach when components start choking under real user load? #ReactJS #WebDevelopment #JavaScript #TechLeadership #SoftwareArchitecture #PerformanceOptimization #Rankue #Vonyex
To view or add a comment, sign in
-
🚀 Redux Thunk vs Redux Saga – When to Use Which? Okay, real talk – if you’ve worked with Redux, you know it’s great for keeping state predictable. But then comes the messy part: async stuff. That’s where Thunk and Saga come in… and honestly, many devs get stuck wondering: “Which one should I use?” Here’s how I see it: Thunk – The Simple & Chill Option Lets your action creators return a function instead of just an object. Perfect for quick API calls or simple async tasks. const fetchUser = (id) => async (dispatch) => { dispatch({ type: 'LOADING_USER' }); const data = await fetch(`/api/users/${id}`).then(res => res.json()); dispatch({ type: 'USER_LOADED', payload: data }); }; 👍 When to use it: small to medium apps, easy async flows, beginner-friendly 💡 Fun fact: Thunk is basically just a function. Super simple, no magic tricks. Saga – The Power User’s Choice Uses generator functions to handle async tasks. Great for complex workflows: cancelling requests, debouncing, retries, polling… you name it. function* fetchUserSaga(action) { try { const data = yield call(fetch, `/api/users/${action.payload}`); const json = yield data.json(); yield put({ type: 'USER_LOADED', payload: json }); } catch (err) { yield put({ type: 'USER_ERROR', payload: err }); } } 👍 When to use it: big apps, complex async flows, testable side effects 💡 Fun fact: Generators let you pause and resume async code. It’s like magic – async looks almost synchronous! ✨ 💬 My two cents: Small/medium apps → go with Thunk. Complex async stuff → Saga is your friend. But here’s the fun part: I’ve seen devs argue forever about which is better. Sometimes it’s really just what fits your project and brain. So… what about you? Do you prefer Thunk for simplicity, or Saga for power moves? Let’s swap stories! 👇 #ReactJS #Redux #JavaScript #FrontendDev #WebDevelopment #AsyncProgramming #DevLife
To view or add a comment, sign in
-
-
🎯 Why Every Developer Should Understand the MVC Architecture. When building applications, maintaining clean structure is everything — and that’s exactly what the MVC (Model–View–Controller) pattern helps us achieve. 1️⃣ Model – Handles data logic and state management 2️⃣ View – The user interface built with React components 3️⃣ Controller – Manages events and orchestrates how data flows between Model and View 🔄 Flow of MVC (as shown in the image): (1) User Interaction → (2) Update State → (3) State Changed → (4) Re-render UI Each step represents how React applications handle data and user actions — ensuring a smooth, predictable cycle from input to UI update. 💡 Why it matters: The MVC pattern helps you build scalable apps, simplify debugging, and maintain separation of concerns — even as your React projects grow in complexity. #ReactJS #WebDevelopment #Frontend #SoftwareArchitecture #MVC #JavaScript
To view or add a comment, sign in
-
-
🚀 Launching Verity v1.0.0: The Backend of Your Frontend After months of development, I'm excited to announce Verity v1.0.0 - an open-source data layer that treats server truth seriously. The Problem We're Solving: Modern frontends blur truth-state (server-owned data) and view-state (client UI concerns). This leads to optimistic updates, rollback flicker, and user distrust. Verity's Approach: ✅ Server is the only source of truth ✅ Directive-driven invalidation (server decides what changed) ✅ No optimistic updates — honest loading states instead ✅ Framework-agnostic (Alpine, React, Vue, Svelte) ✅ Multi-client sync via SSE ✅ Level conversion planning for minimal fetching. Perfect for: • Real-time dashboards and operational tools • Multi-user collaboration apps • Financial, healthcare, and compliance systems • Any application where data accuracy matters more than perceived speed What's included: 📦 Framework-agnostic core library 🔌 Adapters for Alpine.js, React, Vue, and Svelte 📚 Complete documentation with real-world examples 🛠️ Visual devtools for debugging 🎯 Production-ready examples (invoices, manufacturing, healthcare) Available now on npm: npm install verity-dl Docs: https://verity.yidi.sh GitHub: https://lnkd.in/epi6-HAe #opensource #webdev #javascript #frontend #dataengineering #softwaredevelopment
To view or add a comment, sign in
-
Ever wanted to transform location inputs into rich, real-time weather data in your web application? 🤔 In our latest YouTube tutorial, we walk you through how to: ✅ Integrate the Weatherstack API with Node.js ✅ Build a backend + frontend connection for live weather updates ✅ Display temperature, humidity, wind, and UV data dynamically ✅ Visualize weather changes in real time 🎥 Watch the full tutorial on our YouTube channel: https://lnkd.in/g6KVPUmQ 🧠 Try the API for yourself: https://weatherstack.com Perfect for developers exploring API integration, Node.js, or data visualization! #NodeJS #WeatherAPI #WebDevelopment #JavaScript #APIintegration #apilayer #Weatherstack
To view or add a comment, sign in
-
Just spotted Next.js's new Cache Components feature, and it might be the smartest solution to the age-old static vs dynamic rendering headache 🤯 The problem it solves is brilliant: Most pages have BOTH static and dynamic parts. Instead of choosing one approach for the entire page, Cache Components lets you mark specific UI sections as cacheable. What this means in practice: - Static shell loads instantly (fast initial load) - Dynamic parts stream in as they're ready - You control what gets cached and for how long with 'use cache' - No more awkward route segment config hacks After years of dancing between getStaticProps and getServerSideProps (and explaining the difference to junior devs 100 times), this feels like a genuine step forward. The Suspense integration is particularly elegant. Anyone already implementing this on production apps? Drop me a DM - I'd love to hear about your experience with performance improvements, especially if you're moving from a fully dynamic setup. #NextJS #WebPerformance #ReactDevelopment #FrontendDev https://lnkd.in/ecwAuWqD
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