<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sperez927</title>
    <description>The latest articles on DEV Community by sperez927 (@sperez927).</description>
    <link>https://dev.to/sperez927</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1217864%2F7e41eba0-aee8-4433-947f-12191db9f234.jpeg</url>
      <title>DEV Community: sperez927</title>
      <link>https://dev.to/sperez927</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sperez927"/>
    <language>en</language>
    <item>
      <title>Slice Your JS: Lazy Load Components with React + Vite + Dynamic Imports</title>
      <dc:creator>sperez927</dc:creator>
      <pubDate>Tue, 03 Jun 2025 14:49:47 +0000</pubDate>
      <link>https://dev.to/sperez927/slice-your-js-lazy-load-components-with-react-vite-dynamic-imports-mp8</link>
      <guid>https://dev.to/sperez927/slice-your-js-lazy-load-components-with-react-vite-dynamic-imports-mp8</guid>
      <description>&lt;p&gt;🚫 Problem: Big Bundles, Slow First Loads&lt;/p&gt;

&lt;p&gt;Modern apps ship huge bundles. Tools like Vite and Webpack support code splitting, but it's often underused.&lt;br&gt;
Here's how we dropped initial JS size by 40% by lazy-loading non-critical UI in Vite.&lt;/p&gt;

&lt;p&gt;✅ Solution: Dynamic Import + &lt;code&gt;React.lazy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Assume we have a heavy component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Chart() {
  // big lib like recharts, visx, or d3
  return &amp;lt;div&amp;gt;Heavy Chart&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of importing normally:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import Chart from "./Chart"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;React.lazy&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const Chart = React.lazy(() =&amp;gt; import(./Chart));&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Wrap it with &lt;code&gt;&amp;lt;suspense&amp;gt;&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;📊 Result&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initial load time down ~40% on mobile&lt;/li&gt;
&lt;li&gt;Less JS execution blocking Time to Interactive&lt;/li&gt;
&lt;li&gt;Better Lighthouse scores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧪 Vite Handle the Split&lt;/p&gt;

&lt;p&gt;In Vite, you'll now see &lt;code&gt;Chart.[hash].js&lt;/code&gt; as separate chunk. Automatically lazy-loaded when needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist/
├── index.html
├── assets/
│   ├── main.[hash].js
│   └── Chart.[hash].js   ← ✅ Lazy-loaded!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔧 Bonus Tips&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Group multiple lazy components with &lt;code&gt;import()&lt;/code&gt; + &lt;code&gt;Promise.all&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Always provide a &lt;code&gt;&amp;lt;fallback&amp;gt;&lt;/code&gt; for UX&lt;/li&gt;
&lt;li&gt;Profile with DevTools -&amp;gt; Network tab -&amp;gt; disable cache -&amp;gt; reload&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Takeaway&lt;/p&gt;

&lt;p&gt;If your app feels bloated - don't refactor the whole thing. Just start lazy-loading where it hurts most.&lt;/p&gt;

</description>
      <category>vite</category>
      <category>react</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Stop Over-Rerenders: Smarter State Sharing in React with `useContextSelector`</title>
      <dc:creator>sperez927</dc:creator>
      <pubDate>Tue, 03 Jun 2025 14:32:08 +0000</pubDate>
      <link>https://dev.to/sperez927/stop-over-rerenders-smarter-state-sharing-in-react-with-usecontextselector-45d7</link>
      <guid>https://dev.to/sperez927/stop-over-rerenders-smarter-state-sharing-in-react-with-usecontextselector-45d7</guid>
      <description>&lt;p&gt;🚫 Problem: Global Context = Silent Performance Killer&lt;/p&gt;

&lt;p&gt;React's Context API is often misused as global state. It works - until updates to one part of the state cause &lt;strong&gt;every consumer&lt;/strong&gt; to re-render.&lt;br&gt;
We ran into this on a dashboard with many components reading shared filters. One toggle = full tree re-render. Not okay.&lt;/p&gt;

&lt;p&gt;✅ Solution: Replace &lt;code&gt;useContext&lt;/code&gt; with &lt;code&gt;useContextSelector&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install the &lt;strong&gt;context-selector&lt;/strong&gt; lib:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install use-context-selector&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Then replace:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const { filters } = useContext(AppContext);&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;With:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const filters = useContextSelector(AppContext, ctx =&amp;gt; ctx.filters)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now only the components that care about &lt;code&gt;filters&lt;/code&gt; will re-render.&lt;/p&gt;

&lt;p&gt;🧪 Working Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {
  createContext,
  useContextSelector,
  useContext,
} from 'use-context-selector';
import React, { useState } from 'react';

const AppContext = createContext(null);

function Provider({ children }) {
  const [count, setCount] = useState(0);
  const [text, setText] = useState("");

  const value = { count, setCount, text, setText };
  return &amp;lt;AppContext.Provider value={value}&amp;gt;{children}&amp;lt;/AppContext.Provider&amp;gt;;
}

function CountDisplay() {
  const count = useContextSelector(AppContext, ctx =&amp;gt; ctx.count);
  console.log('Render: CountDisplay');
  return &amp;lt;div&amp;gt;Count: {count}&amp;lt;/div&amp;gt;;
}

function TextDisplay() {
  const text = useContextSelector(AppContext, ctx =&amp;gt; ctx.text);
  console.log('Render: TextDisplay');
  return &amp;lt;div&amp;gt;Text: {text}&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Toggling one field &lt;strong&gt;no longer rerenders both&lt;/strong&gt;. Easy win, real speed boost.&lt;/p&gt;

&lt;p&gt;🧠 Takeaway&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoid &lt;code&gt;useContext&lt;/code&gt; for frequently-updated state&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useContextSelector&lt;/code&gt; = scoped updates + happy FPS&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>performance</category>
      <category>redux</category>
      <category>frontend</category>
    </item>
    <item>
      <title>AntD Tables Lag? Try This One Simple Virtualization Fix</title>
      <dc:creator>sperez927</dc:creator>
      <pubDate>Fri, 30 May 2025 19:16:12 +0000</pubDate>
      <link>https://dev.to/sperez927/antd-tables-lag-try-this-one-simple-virtualization-fix-5746</link>
      <guid>https://dev.to/sperez927/antd-tables-lag-try-this-one-simple-virtualization-fix-5746</guid>
      <description>&lt;h2&gt;
  
  
  🚫 Problem: AntD Tables Aren’t Fast By Default
&lt;/h2&gt;

&lt;p&gt;Ant Design is a solid UI framework — until you throw large datasets into its default table.&lt;/p&gt;

&lt;p&gt;We were rendering 300+ rows in a dashboard. Scroll lag, janky performance, and heavy DOM loads kicked in fast. It looked good… but felt broken.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Solution: Virtualization with &lt;code&gt;react-window&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We swapped out the AntD &lt;code&gt;&amp;lt;Table /&amp;gt;&lt;/code&gt; component and replaced it with a &lt;code&gt;react-window&lt;/code&gt; virtualized list. The trick? Keep using AntD’s column logic to retain the look and feel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FixedSizeList&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;List&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-window&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;renderRow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;
  &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;itemCount&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;itemSize&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"100%"&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Row&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gave us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistent UI&lt;/li&gt;
&lt;li&gt;Way fewer DOM nodes&lt;/li&gt;
&lt;li&gt;Smooth scrolling even with big datasets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📊 Results&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;~90% fewer DOM nodes&lt;/li&gt;
&lt;li&gt;Scroll FPS doubled&lt;/li&gt;
&lt;li&gt;Page feel instant again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 Takeaway&lt;br&gt;
UI libraries like Ant Design give you power - not always performance. When dealing with big data, virtualize early. It's a one-time switch that saves your UX.&lt;/p&gt;

&lt;p&gt;🔧 Bonus Tips&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;rowKey&lt;/code&gt; in tables to prevent re-renders&lt;/li&gt;
&lt;li&gt;Don't render hidden columns&lt;/li&gt;
&lt;li&gt;Profile performance in Chrome -&amp;gt; DevTools -&amp;gt; Performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 Resources&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;react-window&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ant.design/components/table/" rel="noopener noreferrer"&gt;https://ant.design/components/table/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>react</category>
      <category>performance</category>
      <category>antdesign</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Debounced Search with useEffect + useRef (No UI Jank)</title>
      <dc:creator>sperez927</dc:creator>
      <pubDate>Thu, 29 May 2025 16:00:06 +0000</pubDate>
      <link>https://dev.to/sperez927/debounced-search-with-useeffect-useref-no-ui-jank-22b3</link>
      <guid>https://dev.to/sperez927/debounced-search-with-useeffect-useref-no-ui-jank-22b3</guid>
      <description>&lt;p&gt;Optimized a product search bar in a React + AntD app.&lt;br&gt;
🚫 Problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every keystroke triggered API call&lt;/li&gt;
&lt;li&gt;UI felt sluggish, unnecessary re-renders
✅ Fix:&lt;/li&gt;
&lt;li&gt;Added debounced search via &lt;code&gt;useEffect&lt;/code&gt; + &lt;code&gt;setTimeout&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Used &lt;code&gt;useRef&lt;/code&gt; to track the time&lt;/li&gt;
&lt;li&gt;Disabled input while loading&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 Code Snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  const timer = setTimeout(() =&amp;gt; search(query), 400);
  return () =&amp;gt; clearTimeout(timer);
}, [query]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚡ Search is smoother, fewer network calls, happier users.&lt;/p&gt;

</description>
      <category>react</category>
      <category>uxdesign</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Compressing Critical CSS Payloads Without Breaking Layout</title>
      <dc:creator>sperez927</dc:creator>
      <pubDate>Thu, 29 May 2025 15:56:40 +0000</pubDate>
      <link>https://dev.to/sperez927/compressing-critical-css-payloads-without-breaking-layout-1838</link>
      <guid>https://dev.to/sperez927/compressing-critical-css-payloads-without-breaking-layout-1838</guid>
      <description>&lt;p&gt;Revisited global styles in a legacy React app.&lt;br&gt;
🚫 Before:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global CSS: 240KB uncompressed&lt;/li&gt;
&lt;li&gt;No purging of unused styles
✅ Fix:&lt;/li&gt;
&lt;li&gt;Switched to Tailwind w/&lt;code&gt;@layer&lt;/code&gt; and &lt;code&gt;@apply&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enabled PurgeCSS in production&lt;/li&gt;
&lt;li&gt;Inlined above-the-fold critical styles
📉 Result: CSS payload dropped to 288KB
⚡ First Contentful Paint improved by ~400ms (Lighthouse)
💡 CSS doesn't need to be big to be powerful.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>css</category>
      <category>webperf</category>
      <category>devlog</category>
    </item>
    <item>
      <title>Lazy Loading Above-the-Fold images Without Killing LCP</title>
      <dc:creator>sperez927</dc:creator>
      <pubDate>Wed, 28 May 2025 01:53:48 +0000</pubDate>
      <link>https://dev.to/sperez927/lazy-loading-above-the-fold-images-without-killing-lcp-1hmf</link>
      <guid>https://dev.to/sperez927/lazy-loading-above-the-fold-images-without-killing-lcp-1hmf</guid>
      <description>&lt;p&gt;Rebuilt the product listing page for a multi-vendor marketplace using React + AntD.&lt;br&gt;
🚫 &lt;strong&gt;Old setup&lt;/strong&gt;: &lt;code&gt;img&lt;/code&gt; tags with lazy loading on every product (including above-the-fold)&lt;br&gt;
✅ &lt;strong&gt;Fix&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;"Eager-load first 6 images (above-the-fold)"&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;**"Switch remaining to &lt;code&gt;loading="lazy"&lt;/code&gt;"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Used &lt;code&gt;IntersectionObserver&lt;/code&gt; for smooth fade-ins"&lt;/strong&gt; 
📉 Largest Contentful Paint dropped by 230ms (Chrome DevTools audit)
*&lt;em&gt;Code Insight:&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img
  src={product.image}
  loading={index &amp;lt; 6 ? "eager" : "lazy"}
  alt={product.name}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Small changes, big wins.&lt;/p&gt;

&lt;h1&gt;
  
  
  #reactjs #fronted #webperformance #ux
&lt;/h1&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>webperformanace</category>
      <category>uxdesign</category>
    </item>
  </channel>
</rss>
