<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ilenia Scala on Medium]]></title>
        <description><![CDATA[Stories by Ilenia Scala on Medium]]></description>
        <link>https://medium.com/@ilenia.scala?source=rss-ef6855d6613d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HwXT_fYYIB1H0d2u</url>
            <title>Stories by Ilenia Scala on Medium</title>
            <link>https://medium.com/@ilenia.scala?source=rss-ef6855d6613d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:35:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ilenia.scala/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[⚛️Did someone say “React Hooks”? Here’s the guide for developers.]]></title>
            <link>https://javascript.plainenglish.io/%EF%B8%8Fdid-someone-say-react-hooks-heres-what-you-need-to-know-0b17f338b9bd?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b17f338b9bd</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Thu, 24 Jul 2025 15:04:25 GMT</pubDate>
            <atom:updated>2025-07-24T23:19:58.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xr0RzyT_ZxWDlu0O7S5Yjg.jpeg" /></figure><p>React provides a powerful set of <strong>Hooks</strong> that let you manage <strong>state</strong>, <strong>side effects</strong>, <strong>performance</strong>, and <strong>DOM interaction</strong> inside functional components.</p><p>In this article, we’ll dive into the most important and often confused hooks — exploring their purpose, key differences, best practices, and real-world use cases — so you can write <strong>cleaner, faster, and more maintainable React code</strong>.</p><h3>🔗useState: local state management</h3><h4>What it is</h4><p>useState is the simplest way to manage <strong>local state</strong> inside a functional component.</p><pre>const [count, setCount] = useState(0);</pre><h4>When to use it</h4><ul><li>To manage basic UI state</li><li>Form inputs, toggles, counters, modal visibility</li></ul><h4>Best practices</h4><p>If your next state depends on the previous one, use the callback form:</p><pre>setCount(prev =&gt; prev + 1);</pre><h3>🔗useReducer: an alternative to useState for complex state</h3><h4>What it is</h4><p>A hook designed for <strong>complex state logic</strong>, or when multiple sub-values are managed together.</p><pre>const [state, dispatch] = useReducer(reducer, initialState);</pre><h4>When to use it</h4><ul><li>State with multiple fields</li><li>Complex updates or branching logic</li><li>You prefer a Redux-style state pattern</li></ul><h4>Best practices</h4><ul><li>Keep action types and the reducer function well organized</li><li>Use it when useState becomes too verbose or scattered</li></ul><h3>🔗useEffect: managing side effects</h3><h4>What it is</h4><p>Runs <strong>side effects</strong> after the component renders — things like API calls, DOM manipulations, or subscriptions.</p><pre>useEffect(() =&gt; {<br>  // do something here<br>  return () =&gt; {<br>    // optional cleanup<br>  };<br>}, [dependencies]);</pre><h4>When to use it</h4><ul><li>Fetching data from APIs</li><li>Subscribing/unsubscribing to events</li><li>Working with timers or animations</li></ul><h4>Best practices</h4><ul><li>Always define your <strong>dependency array</strong></li><li>Use the <strong>cleanup function</strong> when needed</li><li>Avoid placing heavy or unnecessary logic inside</li></ul><h3>🔗useMemo: avoid expensive recalculations</h3><h4>What it is</h4><p>Memoizes a <strong>computed value</strong> so it only recalculates when dependencies change.</p><pre>const sortedItems = useMemo(() =&gt; {<br>  return items.sort((a, b) =&gt; a.value - b.value);<br>}, [items]);</pre><h4>When to use it</h4><ul><li>Costly calculations (sorting, filtering, transforms)</li><li>Derived data for rendering</li><li>Avoiding unnecessary recalculations on re-renders</li></ul><h4>Best practices</h4><ul><li>Don’t use it for every value — <strong>optimize only when needed</strong></li><li>Don’t use it for side effects</li></ul><h3>🔗useCallback: memoize functions</h3><h4>What it is</h4><p>Returns a <strong>memoized version of a function</strong>, useful to prevent re-renders when passing functions to child components.</p><pre>const handleClick = useCallback(() =&gt; {<br>  doSomething();<br>}, [dependency]);</pre><h4>When to use it</h4><ul><li>Passing functions to optimized child components (React.memo)</li><li>Preventing re-renders caused by unstable function references</li><li>When a function is used inside a useEffect or useMemo</li></ul><h4>Best practices</h4><ul><li>Don’t overuse — readability matters</li><li>Avoid wrapping all functions by default</li></ul><h3>🔗useRef: persistent values and DOM access</h3><h4>What it is</h4><p>Provides a mutable object that <strong>persists between renders</strong> without triggering a re-render when updated.</p><pre>const inputRef = useRef(null);<br><br>useEffect(() =&gt; {<br>  inputRef.current.focus();<br>}, []);</pre><h4>When to use it</h4><ul><li>Access DOM nodes directly</li><li>Store values that don’t need to cause re-renders (e.g. timeouts, previous values, flags)</li></ul><h4>Best practices</h4><ul><li>Don’t use it to hold display state (prefer useState)</li><li>Ideal for <strong>imperative logic</strong> and non-reactive data</li></ul><h3>🧪 Real-world example</h3><pre>function SearchableList({ items }) {<br>  const [query, setQuery] = useState(&#39;&#39;);<br>  const inputRef = useRef(null);<br><br>  useEffect(() =&gt; {<br>    inputRef.current.focus();<br>  }, []);<br><br>  const filteredItems = useMemo(() =&gt; {<br>    return items.filter(item =&gt; item.toLowerCase().includes(query.toLowerCase()));<br>  }, [items, query]);<br><br>  const handleChange = useCallback((e) =&gt; {<br>    setQuery(e.target.value);<br>  }, []);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input ref={inputRef} value={query} onChange={handleChange} /&gt;<br>      &lt;ul&gt;<br>        {filteredItems.map(item =&gt; &lt;li key={item}&gt;{item}&lt;/li&gt;)}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>✅ Final Thoughts</p><p>💡 Understand the intent of each hook — don’t misuse them interchangeably.</p><p>⚠️ Avoid premature optimization — only use useMemo/useCallback when needed.</p><p>🧠 Think in terms of rendering — ask yourself: “Does this need to trigger a re-render?”</p><p>If you found this guide useful, give it a 💙, drop a comment, or share it with a React dev you know!</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏️<strong>️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b17f338b9bd" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/%EF%B8%8Fdid-someone-say-react-hooks-heres-what-you-need-to-know-0b17f338b9bd">⚛️Did someone say “React Hooks”? Here’s the guide for developers.🌀</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lit + Vite for Angular and React Devs: The Guide I Wish I Had Read Sooner]]></title>
            <link>https://javascript.plainenglish.io/a-practical-guide-to-implementing-lit-with-vite-in-angular-and-react-projects-33d929e0f4e0?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/33d929e0f4e0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[lit]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Thu, 08 May 2025 13:33:02 GMT</pubDate>
            <atom:updated>2025-05-14T07:51:22.327Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D6BUa1R75jeq4ZF_gDoIXA.jpeg" /></figure><p>Want to take your Web Components to the next level, making them reusable, performant, and easily integrable into modern frontend architectures? After exploring the basics of Web Components <a href="https://medium.com/javascript-in-plain-english/web-components-the-hidden-superheroes-of-modern-frontend-%EF%B8%8F-88caa4ed3f5f">(if you haven’t read it yet click here)</a>, it’s time to dive into <strong>Lit</strong>: an efficient and precise library that makes web component development more reactive, declarative, and modern.</p><p>With Lit, you can say goodbye to manual complexity: reactivity is elegantly managed, templating is clear, and the code remains clean. And with <strong>Vite</strong>, your development environment will be lightning-fast and modern, ready for integration with Angular and React.</p><h3>📦 What is Lit? The Ideal Library for Web Components</h3><p>Lit is a lightweight library developed by Google, designed to create Web Components based on standards, with a focus on performance, clarity, and code compactness.</p><p>Lit mainly consists of:</p><ul><li><strong>LitElement</strong>: a base class from which your components inherit, with a reactive lifecycle and a highly efficient rendering system.</li><li><strong>lit-html</strong>: a templating library that allows you to write HTML with JavaScript in a declarative and performant way, updating only the parts of the DOM that have actually changed.</li></ul><h3>Why Use Lit? Key Advantages</h3><ul><li>High performance thanks to lit-html, with targeted and fast DOM updates.</li><li>Simplified development: less boilerplate, more clarity.</li><li>Native reactivity in properties.</li><li>Full interoperability: Web Components created with Lit work in Angular, React, Vue, and Vanilla JS.</li><li>Lightweight bundle: ideal for modern, high-performance apps.</li><li>Expressive templating with JavaScript.</li><li>Encapsulated CSS with Shadow DOM.</li><li>Standard-oriented: no framework lock-in.</li><li>A vibrant ecosystem: supported by Google, with excellent documentation.</li></ul><h3>⚡ Vite + Lit: A Winning Combination</h3><p>Vite is a next-generation build tool that leverages ES modules to offer several key advantages:</p><ul><li><strong>Instant development server</strong>, even for large projects, with a fast startup time.</li><li><strong>Responsive Hot Module Replacement (HMR)</strong> for quick updates during development, which significantly speeds up the development workflow.</li><li><strong>Optimized production builds</strong> using Rollup, which ensures that your final output is minimal and efficient.</li><li><strong>Out-of-the-box support for TypeScript and CSS</strong>, making it easier to work with modern JavaScript tools.</li><li><strong>Native compatibility with Lit</strong>, thanks to the shared use of ES modules, ensuring seamless integration.</li><li><strong>TypeScript integration</strong>: Vite has robust support for TypeScript, which allows for type-checking during development, reducing potential runtime errors in production.</li></ul><p>These features make Vite a perfect companion for Lit, creating a fast and efficient development environment with minimal configuration.</p><h4>Setup Example with Vite</h4><pre>npm create vite@latest my-lit-vite-project -- --template vanilla-ts<br>cd my-lit-vite-project<br>npm install lit</pre><p>Then, in index.html:</p><pre>&lt;script type=&quot;module&quot; src=&quot;/src/components/my-element.ts&quot;&gt;&lt;/script&gt;<br>&lt;my-element name=&quot;Vite&quot;&gt;&lt;/my-element&gt;</pre><p>With a minimal vite.config.ts:</p><pre>import { defineConfig } from &#39;vite&#39;;<br>export default defineConfig({});</pre><h4>📁 Optimal Project Structure for Lit with Vite and TypeScript</h4><pre>my-lit-project/<br>│<br>├── index.html                # Entry point: loads the Web Components<br>├── vite.config.ts           # Vite configuration (plugins, aliases, etc.)<br>├── tsconfig.json            # TypeScript configuration<br>├── package.json<br>├── public/                  # Static public files (favicon, images)<br>└── src/<br>    ├── main.ts              # Entry JS/TS file (could be minimal)<br>    ├── components/<br>    │   ├── MyElement.ts     # Lit Web Component (PascalCase, optional &quot;Element&quot; suffix)<br>    │   └── index.ts         # Barrel file to export all components<br>    ├── styles/<br>    │   └── theme.css        # Global variables or shared styles<br>    └── utils/<br>        └── helpers.ts       # Reusable functions</pre><h4>✅ Best Practices in Lit Projects</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*qWVgJZPtMu-LGf1vPVwQSQ.png" /></figure><h3>🔌 Integrating Lit with Angular</h3><p>Angular natively supports Web Components. To use a Lit component:</p><ul><li>Import the built JS of the Lit component (e.g., from vite build).</li><li>Use bindings and events in the template just like you would with Angular components:</li></ul><pre>&lt;my-element<br>  [greeting]=&quot;angularGreeting&quot;<br>  [name]=&quot;user.name&quot;<br>  [counter]=&quot;initialCounter&quot;<br>  (counter-updated)=&quot;handleLitCounterEvent($event)&quot;&gt;<br>&lt;/my-element&gt;</pre><p>Handling the event in Angular:</p><pre>handleLitCounterEvent(event: CustomEvent) {<br>  this.litEventData = event.detail;<br>}</pre><p>🔍 Angular 19: Is CUSTOM_ELEMENTS_SCHEMA Still Needed?</p><p>It depends on how you use Angular:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*9kQnQIn6gW_IaVvWhaJxig.png" /></figure><p>If you use standalone components (available from Angular 14+ and fully supported in Angular 16+), Angular <strong>no longer validates custom HTML tags</strong>, so you can use Web Components <strong>without additional configuration</strong>.</p><p>Example with a standalone component:</p><pre>@Component({<br>  standalone: true,<br>  selector: &#39;app-root&#39;,<br>  template: `&lt;my-element name=&quot;Angular&quot;&gt;&lt;/my-element&gt;`<br>})<br>export class AppComponent {}</pre><p>If you’re using a classic NgModule, you need to <strong>declare </strong><strong>CUSTOM_ELEMENTS_SCHEMA</strong>:</p><pre>import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from &#39;@angular/core&#39;;<br><br>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [BrowserModule],<br>  bootstrap: [AppComponent],<br>  schemas: [CUSTOM_ELEMENTS_SCHEMA]<br>})<br>export class AppModule {}</pre><h3>⚛️ Integrating Lit with React (with @lit/react)</h3><p>For solid integration between React and Lit, the @lit/react library is the ideal tool.</p><p>Setup:</p><pre>npm install @lit/react</pre><p>React Wrapper:</p><pre>import { createComponent } from &#39;@lit/react&#39;;<br>import { MyElement as MyElementClass } from &#39;./my-element&#39;;<br>import &#39;./my-element.js&#39;;<br><br>export const MyReactWrappedElement = createComponent({<br>  tagName: &#39;my-element&#39;,<br>  elementClass: MyElementClass,<br>  react: React,<br>  events: { onCounterUpdated: &#39;counter-updated&#39; }<br>});</pre><p>Usage in React</p><pre>&lt;MyReactWrappedElement<br>  greeting={reactGreeting}<br>  name={user.name}<br>  counter={10}<br>  onCounterUpdated={handleCounterUpdate}<br>/&gt;</pre><h3>📦 Distribution of Lit Web Components</h3><p>Once you have developed your Lit Web Components, it’s time to distribute them for use in different projects. Here’s how you can do it effectively:</p><h3>1. Build the Web Component for Distribution</h3><p>To distribute your Lit Web Component, you need to build it into a form that can be easily consumed by others. With Vite, the process is seamless. Use Vite’s built-in Rollup configuration to bundle your components into a single file ready for distribution.</p><pre>npm run build</pre><p>This command will create a production-ready version of your component in the dist/ directory, which will include all necessary dependencies and optimized files.</p><h3>2. Publish to npm</h3><p>You can publish your Lit Web Components to npm to make them available for others to install and use. To do so, follow these steps:</p><ul><li><strong>Step 1</strong>: Make sure you have a package.json with the correct metadata for your component. This includes the name, version, and description of your component.</li></ul><pre>{<br>  &quot;name&quot;: &quot;my-lit-component&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;dist/my-element.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;vite build&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;lit&quot;: &quot;^2.0.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;vite&quot;: &quot;^4.0.0&quot;<br>  }<br>}</pre><ul><li><strong>Step 2</strong>: Create an account on <a href="https://www.npmjs.com/">npm</a> if you haven’t already.</li><li><strong>Step 3</strong>: Log in to your npm account using the following command:</li></ul><pre>npm login</pre><p><strong>Step 4</strong>: Publish the package to npm:</p><pre>npm publish</pre><p>After this, your component will be publicly available and can be installed by others using:</p><pre>npm install my-lit-component</pre><h3>3. CDN Hosting</h3><p>Alternatively, you can host your component on a CDN (Content Delivery Network) to make it easily accessible. Services like <a href="https://www.jsdelivr.com/">jsDelivr</a> or <a href="https://unpkg.com/">UNPKG</a> allow you to host your JavaScript files without needing a server.</p><p>To do this, you can upload your built dist/ files to a GitHub repository and access them via the CDN:</p><pre>&lt;script type=&quot;module&quot; src=&quot;https://cdn.jsdelivr.net/gh/username/my-lit-component@1.0.0/dist/my-element.js&quot;&gt;&lt;/script&gt;</pre><p>This method allows users to access your component directly via a URL without the need to install it via npm.</p><h3>4. Versioning and Updates</h3><p>When distributing Web Components, it’s important to manage versioning. Follow semantic versioning principles to communicate updates and changes:</p><ul><li><strong>Major version</strong>: When there are breaking changes.</li><li><strong>Minor version</strong>: When you add new features in a backwards-compatible manner.</li><li><strong>Patch version</strong>: For minor fixes and optimizations.</li></ul><p>Whenever you update your component, update the version in package.json, rebuild it, and republish it to npm.</p><h3>✅ Conclusion: Lit + Vite for a Powerful Frontend</h3><p>Lit represents a modern, elegant, and standards-compliant solution for building Web Components, making them ready for use in any frontend context. With <strong>Vite</strong>, you get a fast, modular development environment aligned with modern technologies.</p><p>Whether you’re working on Angular, React, or standalone projects, <strong>Lit integrates seamlessly</strong>, offering performance, maintainability, and interoperability. A true catalyst for scalable and well-structured frontends.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33d929e0f4e0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/a-practical-guide-to-implementing-lit-with-vite-in-angular-and-react-projects-33d929e0f4e0">Lit + Vite for Angular and React Devs: The Guide I Wish I Had Read Sooner</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Components: The Superheroes of the Frontend You Need to Know — A Complete Guide ‍♂️]]></title>
            <link>https://javascript.plainenglish.io/web-components-the-hidden-superheroes-of-modern-frontend-%EF%B8%8F-88caa4ed3f5f?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/88caa4ed3f5f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 10:25:57 GMT</pubDate>
            <atom:updated>2025-05-09T07:15:12.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0Mq8lowzjMADP3RS-zP2g.jpeg" /></figure><p>Have you ever found yourself battling against code duplication? Wishing for a way to create truly reusable UI components that work everywhere, regardless of the current JavaScript framework? If you’re nodding, then you’re in the right place.</p><p>In the fast-paced world of frontend development, we’re often immersed in a “jungle” of frameworks and libraries: React, Vue, Angular, Svelte… Each with its strengths, but also with its own rules and lifecycle. Sometimes, however, a desire arises: what if we could build parts of our user interface using native web standards, ensuring longevity and interoperability?</p><p>Well, get ready to discover Web Components, the hidden superheroes that the browser itself provides us with. They are not just another framework to learn, but a set of powerful technologies that will allow you to create custom, encapsulated, and reusable HTML elements like never before. Buckle up, we’re about to demystify them!</p><h3><strong>But What Exactly Are These Web Components?</strong></h3><p>In simple terms, Web Components are a set of standard browser APIs that allow you to do something almost magical: create your own custom HTML elements. Think of &lt;my-cool-button&gt; or &lt;user-profile-card&gt; that work just like the native &lt;button&gt; or &lt;div&gt; tags, but with your logic, your style, and your internal structure.</p><p>The beauty lies in the fact that they are:</p><ul><li><strong>Reusable:</strong> Write the code once, use it in any project.</li><li><strong>Encapsulated:</strong> Internal styles and behaviors are protected from the rest of the page — goodbye CSS conflicts!</li><li><strong>Interoperable:</strong> They work with any JavaScript framework… or even without one!</li><li><strong>Standard:</strong> They are part of the web platform, not a fleeting trend.</li></ul><p>They are similar to the components you might know from React or Vue, but with the superpower of being native to the browser.</p><h3><strong>The 4 Fundamental Pillars</strong></h3><p>Web Components stand on four key technologies that work together synergistically:</p><h4><strong>1. Custom Elements: Create Your Own HTML Tags!</strong></h4><p>This is the foundation. The Custom Elements API allows you to define the logic and behavior of your new HTML tags.</p><pre>// Define the class for my new element<br>class MyCustomElement extends HTMLElement {<br>  constructor() {<br>    super(); // Always call super() first in the constructor!<br>    console.log(&#39;Custom element created!&#39;);<br>    // You can do initial setup here<br>  }<br><br>  // ... other lifecycle methods ...<br>}<br><br>// Register my new element with the browser<br>// Note: the name MUST contain a hyphen!<br>customElements.define(&#39;my-custom-element&#39;, MyCustomElement);<br><br>// ✨ Pro Tip: Conditional Registration ✨<br>// To avoid errors if the script is loaded multiple times (e.g., HMR, testing),<br>// it&#39;s good practice to check if the element is already defined:<br>if (!customElements.get(&#39;my-robust-element&#39;)) {<br>  class MyRobustElement extends HTMLElement { /* ... */ }<br>  customElements.define(&#39;my-robust-element&#39;, MyRobustElement);<br>}</pre><p>Now you can use &lt;my-custom-element&gt;&lt;/my-custom-element&gt; directly in your HTML! As we&#39;ll see shortly, these elements also have their own specific lifecycle.</p><h4><strong>2. </strong>Shadow DOM: The Browser’s Encapsulation Mechanism</h4><p>Have you ever had problems with CSS styles “bleeding” out of a component and affecting the rest of the page (or vice versa)? The Shadow DOM is the solution!</p><p>It allows you to create a separate, hidden DOM tree inside your Custom Element. Think about how the native &lt;video&gt; element works: it has a lot of internal controls (play, pause, volume), but you only see the &lt;video&gt; tag. That&#39;s the magic of the Shadow DOM (or something very similar)!</p><pre>class MyStyledElement extends HTMLElement {<br>  constructor() {<br>    super();<br>    // Create and attach a Shadow Root to my element<br>    // mode: &#39;open&#39; allows external access via element.shadowRoot (useful for debugging/testing)<br>    // mode: &#39;closed&#39; prevents it, for tighter encapsulation (but less flexible)<br>    const shadow = this.attachShadow({ mode: &#39;open&#39; });<br><br>    const style = document.createElement(&#39;style&#39;);<br>    style.textContent = `<br>      /* These styles only apply INSIDE the Shadow DOM! */<br>      p { color: rebeccapurple; font-weight: bold; }<br>      :host { display: block; padding: 1rem; border: 1px solid #ccc; }<br>    `;<br>    const info = document.createElement(&#39;p&#39;);<br>    info.textContent = &#39;This text is encapsulated in the Shadow DOM!&#39;;<br><br>    shadow.appendChild(style);<br>    shadow.appendChild(info);<br>  }<br>}<br>customElements.define(&#39;my-styled-element&#39;, MyStyledElement);</pre><p>Style encapsulation is incredibly powerful: styles defined inside the Shadow DOM do not affect the external page, and global page styles do not enter and modify the inside of the component. This effectively prevents conflicts. There are ways to allow controlled customization from the outside, such as using CSS Custom Properties (var(--my-color)) or CSS Shadow Parts (::part(part-name)), but these must be explicitly planned by the component developer.</p><h4><strong>3. HTML Templates (</strong><strong>&lt;template&gt; and </strong><strong>&lt;slot&gt;): Reusable Blueprints</strong></h4><p>The &lt;template&gt; tag allows you to define a block of HTML that isn&#39;t rendered by the browser until you activate it via JavaScript. It&#39;s perfect for defining the internal structure (often of the Shadow DOM) of your components in an efficient and performant way, because the browser parses it only once.</p><pre>&lt;template id=&quot;my-card-template&quot;&gt;<br>  &lt;style&gt;<br>    .card { border: 1px solid gray; padding: 15px; border-radius: 5px; }<br>    .title { font-weight: bold; }<br>  &lt;/style&gt;<br>  &lt;div class=&quot;card&quot;&gt;<br>    &lt;span class=&quot;title&quot;&gt;&lt;slot name=&quot;card-title&quot;&gt;Default Title&lt;/slot&gt;&lt;/span&gt;<br>    &lt;div class=&quot;content&quot;&gt;&lt;slot name=&quot;card-content&quot;&gt;Default content...&lt;/slot&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>  // 💡 Pay attention to the order! 💡<br>  // Make sure the template exists in the DOM before the script tries to access it.<br>  // Either put the script after the template, or wrap the code in a listener:<br>  window.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt; {<br>    class MyCard extends HTMLElement {<br>      constructor() {<br>        super();<br>        const shadow = this.attachShadow({ mode: &#39;open&#39; });<br>        const template = document.getElementById(&#39;my-card-template&#39;);<br>        // Verify that the template was found before cloning it<br>        if (template) {<br>          const content = template.content.cloneNode(true);<br>          shadow.appendChild(content);<br>        } else {<br>          console.error(&#39;Template my-card-template not found!&#39;);<br>        }<br>      }<br>    }<br>    if (!customElements.get(&#39;my-card&#39;)) {<br>      customElements.define(&#39;my-card&#39;, MyCard);<br>    }<br>  });<br>&lt;/script&gt;<br><br>&lt;my-card&gt;<br>  &lt;span slot=&quot;card-title&quot;&gt;My Custom Title&lt;/span&gt;<br>  &lt;p slot=&quot;card-content&quot;&gt;This is the content I want to insert in the card.&lt;/p&gt;<br>&lt;/my-card&gt;</pre><blockquote>📝 <strong>Note to add in the text:</strong></blockquote><blockquote>The content inside &lt;template&gt; tags is not rendered until explicitly cloned in JavaScript. To do this, it is recommended to use template.content.cloneNode(true) to get a complete and ready-to-use copy.</blockquote><p>The &lt;slot&gt; tag is the mechanism that allows for composition: it acts as a placeholder that can be &quot;filled&quot; with markup provided from the outside when you use the component, making it incredibly flexible.</p><h4><strong>4. ES Modules: Import and Export Like a Pro</strong></h4><p>Finally, standard JavaScript modules (import/export) are the native and clean way to define, distribute, and import your Web Components, keeping your code organized and maintainable.</p><pre>// my-button.js<br>export class MyButton extends HTMLElement { /* ... */ }<br>customElements.define(&#39;my-button&#39;, MyButton);<br><br>// main.js<br>import &#39;./my-button.js&#39;; // Import (and execute) the file that defines the component<br><br>// Now you can use &lt;my-button&gt; in your main HTML</pre><p>Important: For the browser to treat the JavaScript file as a module and process the import/export declarations, you must include it in your HTML using type=&quot;module&quot;:</p><pre>&lt;script type=&quot;module&quot; src=&quot;main.js&quot;&gt;&lt;/script&gt;</pre><h3><strong>The Pulsating Heart: The Lifecycle</strong></h3><p>Custom Elements are not static; they have a well-defined lifecycle with specific methods that are called by the browser at key moments:</p><p><strong>1. constructor(): The first one called when an instance of the element is created (e.g., </strong><strong>document.createElement(&#39;my-element&#39;)). Do not access the DOM here; it&#39;s too early! Ideal for:</strong></p><ul><li>Initial setup of internal state.</li><li>Creating the Shadow DOM (attachShadow).</li><li>Binding methods (this.handleClick = this.handleClick.bind(this)).</li></ul><p><strong>2. connectedCallback(): Called every time the element is added to the main document DOM. This is the right place to:</strong></p><ul><li>Manipulate the DOM (internal or external).</li><li>Perform data fetches.</li><li>Add event listeners (to the window, document, or internal nodes).</li></ul><pre>connectedCallback() {<br>  console.log(&#39;Element added to the DOM!&#39;);<br>  // Look for internal elements (preferably in the Shadow DOM)<br>  // ✨ Tip: Use optional chaining (?.) or check if the element exists!<br>  this._internalButton = this.shadowRoot?.querySelector(&#39;button&#39;);<br>  if (this._internalButton) {<br>    this._boundClickHandler = this.handleClick.bind(this); // Create a reference to remove it later<br>    this._internalButton.addEventListener(&#39;click&#39;, this._boundClickHandler);<br>  } else {<br>    console.warn(&#39;Internal button not found!&#39;);<br>  }<br>}<br><br>handleClick() {<br>  console.log(&#39;Button clicked!&#39;);<br>  // ... do something ...<br>}</pre><p>3. disconnectedCallback(): Called every time the element is removed from the DOM. Crucial for cleanup and preventing memory leaks!</p><ul><li>Remove event listeners added in connectedCallback.</li><li>Cancel setInterval or setTimeout.</li><li>Cancel ongoing network requests (e.g., AbortController).</li></ul><pre>disconnectedCallback() {<br>  console.log(&#39;Element removed from the DOM!&#39;);<br>  // Remove the event listener using the same bound reference<br>  if (this._internalButton &amp;&amp; this._boundClickHandler) {<br>    this._internalButton.removeEventListener(&#39;click&#39;, this._boundClickHandler);<br>  }<br>}</pre><p>4. attributeChangedCallback(attributeName, oldValue, newValue): Called when an element&#39;s attribute changes (only for attributes you&#39;ve explicitly told it to &quot;observe&quot;).</p><pre>static get observedAttributes() {<br>  // Declare which HTML attributes (in lowercase!) should trigger the callback<br>  return [&#39;disabled&#39;, &#39;label&#39;, &#39;user-id&#39;];<br>}<br><br>attributeChangedCallback(name, oldValue, newValue) {<br>  // &#39;name&#39; will always be lowercase here<br>  console.log(`Attribute ${name} changed from ${oldValue} to ${newValue}`);<br>  if (name === &#39;disabled&#39;) {<br>    // Update internal state or DOM based on the new value<br>    const button = this.shadowRoot?.querySelector(&#39;button&#39;);<br>    if (button) button.disabled = newValue !== null; // Does the attribute exist? Then disable.<br>  }<br>  // ... handle other attributes ...<br>}</pre><p>Note: Attributes in the DOM are always lowercase (or kebab-case). Even if you might have camelCase properties in JavaScript, when you reflect them as attributes or observe them, you must use the lowercase version.</p><ul><li>adoptedCallback(): Called if the element is moved to a new document (rare case, e.g., using document.adoptNode() with an &lt;iframe&gt;).</li></ul><p>Understanding the lifecycle is essential for writing robust and performant components.</p><h3><strong>Communicating with the Outside: Custom Events</strong></h3><p>Often a component needs to “notify” the outside world when something happens internally (e.g., a click, a value change, completion of an operation). The standard way to do this is to dispatch <strong>CustomEvent</strong>:</p><pre>handleClick() {<br>  console.log(&#39;Internal button clicked, notifying the outside world!&#39;);<br>  // Create a custom event<br>  const myEvent = new CustomEvent(&#39;button-clicked&#39;, {<br>    detail: { // &#39;detail&#39; is the object for passing custom data<br>      timestamp: Date.now(),<br>      message: &#39;The special button was pressed!&#39;<br>    },<br>    bubbles: true, // Allows the event to &quot;bubble up&quot; the DOM tree<br>    composed: true // Allows the event to &quot;cross&quot; Shadow DOM boundaries<br>  });<br>  // Dispatch the event from the element itself<br>  this.dispatchEvent(myEvent);<br>}<br><br>// Whoever uses the component can listen for it like this:<br>// const myElement = document.querySelector(&#39;my-custom-element&#39;);<br>// myElement.addEventListener(&#39;button-clicked&#39;, (event) =&gt; {<br>//   console.log(&#39;Event received!&#39;, event.detail.message);<br>// });</pre><p>Using bubbles: true and composed: true is often useful to allow listeners higher up in the DOM (even outside the Shadow DOM containing the component) to easily catch the event.</p><h3>A Special Consideration: Accessibility (a11y)</h3><p>When we create our custom elements, especially if they are interactive (buttons, inputs, toggles, menus…), we have the responsibility to make them accessible to all users, including those using assistive technologies like screen readers.</p><ul><li>Use semantic HTML elements inside your component whenever possible.</li><li>If you create non-native elements, make sure to add appropriate ARIA roles (e.g., role=&quot;button&quot;, role=&quot;checkbox&quot;).</li><li>Manage ARIA states (e.g., aria-pressed, aria-expanded, aria-disabled).</li><li>Ensure elements are navigable and activatable via keyboard (managing tabindex if necessary).</li></ul><p>Accessibility is not a “nice to have,” but a fundamental part of creating quality web components.</p><h3>Why Web Components Are So “Cool”? (Potential)</h3><p>et’s summarize the advantages that make them a strategic choice:</p><p>✅ Maximum Reusability: Write once, use everywhere.</p><p>🛡️ Solid Encapsulation: Protected styles and logic.</p><p>🤝 Native Interoperability: Work with/without frameworks.</p><p>📜 Standardization and Longevity: Based on stable web APIs.</p><p>🔧 Improved Maintainability: Isolated and focused components.</p><p>🚀 Native Performance: The browser does the heavy lifting.</p><h3><strong>Nobody’s Perfect: Limits and Challenges</strong></h3><p>It’s fair to be honest; Web Components are not a panacea for all ills:</p><ul><li><strong>Learning Curve:</strong> They require a good understanding of native DOM APIs.</li><li><strong>Manual Reactivity:</strong> “Vanilla” Web Components are not reactive by default like framework components. You have to manually manage DOM updates when state or properties change (e.g., via attributeChangedCallback or property setters). Libraries like Lit help enormously with this.</li><li><strong>Tooling and Ecosystem:</strong> Growing, but perhaps not yet as vast as that of more mature frameworks for certain specific needs.</li><li><strong>SEO (Historically):</strong> Modern crawlers handle the Shadow DOM well, but it’s always an aspect to consider for crucial content.</li><li><strong>Server-Side Rendering (SSR):</strong> More complex to implement compared to some frameworks that offer it natively. Declarative Shadow DOM is improving the situation.</li><li><strong>Complex State Management:</strong> For large applications, external patterns or libraries will likely be needed for global state management.</li></ul><h3><strong>Where They Shine Today: Modern Use Cases and Future</strong></h3><p>Despite the challenges, Web Components are already successfully used in many contexts:</p><ul><li><strong>Design Systems:</strong> The ideal choice for reusable UI libraries in large companies (Google Material Web, Salesforce Lightning, GitHub Primer, etc.).</li><li><strong>Micro-Frontends:</strong> Perfect for building independent UI parts.</li><li><strong>Independent Widgets:</strong> Video players, chat, comments embeddable anywhere.</li><li><strong>Integration with Frameworks:</strong> Use them inside React/Vue/Angular, or vice versa.</li><li><strong>Progressive Enhancement:</strong> Adding modern functionality to existing sites.</li></ul><p>The Future? It’s bright. With the evolution of standards (CSS Custom Properties, Constructable Stylesheets, Declarative Shadow DOM, CSS Modules/Scope…), they will become even more powerful and integrated.</p><h3><strong>Conclusion: Adopt Your New Superpowers!</strong></h3><p>Web Components represent a fundamental step towards a more modular, standardized, and resilient web. They are not here to kill frameworks, but to complement them and offer an alternative based on solid standards for creating reusable and future-proof UI.</p><p>They offer real encapsulation, unprecedented interoperability, and the promise of writing code that will last over time. Of course, they require a bit of study, but the long-term benefits can be enormous.</p><p>My advice? Start experimenting! Try building a small component. Explore libraries like Lit that simplify their creation. And don’t forget accessibility!</p><p><strong><em>If you’ve made it this far, thank you very much. If you’d like to share your opinion on the matter or add any insights dear to you, I’m eager to receive them. </em></strong>🙏</p><h4>💡Curious to see Web Components in action? <a href="https://medium.com/javascript-in-plain-english/a-practical-guide-to-implementing-lit-with-vite-in-angular-and-react-projects-33d929e0f4e0">Read this article to discover Lit, Vite, and the implementation with Angular and React.</a></h4><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88caa4ed3f5f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/web-components-the-hidden-superheroes-of-modern-frontend-%EF%B8%8F-88caa4ed3f5f">Web Components: The Superheroes of the Frontend You Need to Know — A Complete Guide 🦸‍♂️</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The CSS Revolution Continues: 10+ Modern Features Igniting Web Innovation in 2025 (+ bonus track)…]]></title>
            <link>https://javascript.plainenglish.io/the-css-revolution-continues-10-modern-features-igniting-web-innovation-in-2025-bonus-track-c5b45170e62a?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5b45170e62a</guid>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 14:18:55 GMT</pubDate>
            <atom:updated>2025-05-08T14:54:18.801Z</atom:updated>
            <content:encoded><![CDATA[<h3>The CSS Revolution Continues: 10 Modern Features You Need to Know in 2025 (+ Bonus Track) 🔥</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvUGsoX_eKMfs6Hr4DLFpQ.jpeg" /></figure><blockquote>“CSS is just for styling, right?”<br><strong> Not anymore. And if you still think that… get ready to change your mind.</strong></blockquote><p>In 2025, CSS has become a powerful tool, capable of:</p><ul><li>handling dynamic layouts</li><li>creating smooth animations without JavaScript</li><li>improving performance</li><li>building more scalable and accessible UIs</li></ul><p>In this article, I’ll show you the most innovative CSS features, with practical examples and actionable tips for your next project.</p><h3>🎯 1. @scope — Localized styles, finally</h3><p>CSS is global by nature. And that… can become a mess.</p><p>With @scope, we can limit the reach of our styles to a single container.<br> No more conflicts, no more ridiculous names like card__button--secondary-light-dark.</p><pre>&lt;div id=&quot;card&quot;&gt;<br>  &lt;p&gt;Inside the scope&lt;/p&gt;<br>&lt;/div&gt;<br>&lt;p&gt;Outside the scope&lt;/p&gt;<br><br>&lt;style&gt;<br>  @scope (#card) {<br>    p {<br>      color: steelblue;<br>    }<br>  }<br>&lt;/style&gt;</pre><p>✅ Only the paragraph inside #card will be blue.</p><p>Perfect for reusable components in a design system.</p><p><strong>📦 Note: </strong><strong>@scope brings a concept similar to style encapsulation into native CSS, but in a declarative way and without external dependencies.</strong></p><p><strong>What about CSS Modules?</strong><br> While not new in 2025, <strong>CSS Modules</strong> are a well-established solution to the global style problem, widely used in React, Vue, and similar environments.<br> They generate unique class names at build time (.button_xyz123) to prevent conflicts — solving the issue upstream via tooling.</p><p>🔍 <strong>Main differences between </strong><strong>@scope and CSS Modules:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*Scqs2ulJeP74-wUrCX0jjQ.png" /></figure><p><strong>In summary</strong>:<br>Use @scope if you want <strong>native scoping</strong> in projects or with Web Components.<br>Stick with <strong>CSS Modules</strong> if you&#39;re working in React or Next.js — it&#39;s still a rock-solid solution.</p><h3>🛡️ 2. @supports — Progressive enhancement, the right way</h3><p>Want to use cutting-edge features without breaking older browsers?</p><p>@supports lets you apply styles <strong>only if the browser supports them</strong>.</p><pre>@supports (display: grid) {<br>  .layout {<br>    display: grid;<br>    grid-template-columns: 1fr 1fr;<br>  }<br>}</pre><p>If Grid is supported, it’s used. Otherwise, you can fall back gracefully.</p><p><strong>📦 Use </strong><strong>@supports like an </strong><strong>if statement in your CSS to make it future-proof.</strong><br>Better UX for users on older browsers, with a baseline layout that still works.</p><h3>🚀 3. content-visibility — Load only what you need</h3><p>Modern websites are full of content — articles, feeds, components, widgets. But here’s the thing: the browser usually <strong>renders everything</strong>, even what’s far outside the viewport. That means extra work, slower performance, and wasted resources.</p><p>Enter content-visibility: auto.<br> 🧠 It tells the browser: <em>“Ignore this section until it’s visible.”</em></p><pre>section {<br>  content-visibility: auto;<br>  contain-intrinsic-size: auto 600px;<br>}</pre><h4>✅ What this does:</h4><ul><li>The section <strong>isn’t rendered at all</strong> (not even layout or paint!) until it scrolls into view.</li><li>The contain-intrinsic-size gives the browser a <strong>placeholder size</strong>, preventing layout shifts when it appears.</li></ul><h3>When to Use It (and When Not To)</h3><h4>Perfect for:</h4><ul><li>Infinite scroll feeds (social, blogs, product lists)</li><li>Long-form content and documentation</li><li>Hidden sections, accordions, toggles</li><li>Components that start off-screen or behind tabs</li></ul><h4>Use with care when:</h4><ul><li>The element affects the surrounding layout</li><li>You need immediate rendering for interactivity</li><li>There’s dynamic height and no estimated size → may cause jumps</li></ul><h4>🤯 Combine It with JavaScript</h4><p>Although content-visibility already defers rendering, you can go even further:<br> 🧠 Load data <strong>only when the section is visible</strong>, just like you would with IntersectionObserver — but with fewer lines of code.</p><pre>&lt;section style=&quot;content-visibility: auto;&quot;&gt;<br>  &lt;!-- Load content when visible --&gt;<br>&lt;/section&gt;</pre><p>Super useful for SPAs, blogs, or dashboards with lots of modular content.</p><h3>📐 4. aspect-ratio — Maintain proportions in one line</h3><p>Say goodbye to padding-top hacks. Now we have aspect-ratio.</p><pre>img {<br>  width: 100%;<br>  aspect-ratio: 16 / 9;<br>}</pre><p>✅ The image remains panoramic even on small screens.</p><p>Perfect for images, videos, and responsive cards.<br>Simplifies responsive layouts without complex JS or wrapper divs.</p><h3>🎬 5. @starting-style — Smoother animations from the start</h3><p>We’ve all seen it:<br> A modal or dropdown animates… but it <strong>starts from the final state</strong> and <em>then</em> animates back.<br> Result? 🥴 A flicker. A glitch. An awkward jump.</p><p>That happens because <strong>CSS transitions normally start from the “computed style”</strong> — and when an element enters the DOM or becomes visible, the browser doesn’t <em>yet</em> know what its “previous” state was.</p><p>But now there’s a fix: <strong>@starting-style</strong>.</p><p>It lets you define the <strong>starting point</strong> of the animation <strong>explicitly</strong>, so the browser knows how to animate smoothly <em>from the very beginning</em> — even on first render.</p><pre>.modal:open {<br>  opacity: 1;<br>  transform: scale(1);<br>  transition: all 0.3s ease;<br><br>  @starting-style {<br>    opacity: 0;<br>    transform: scale(0.9);<br>  }<br>}</pre><h3>Result:</h3><ul><li>The modal <strong>starts invisible and slightly smaller</strong></li><li>It smoothly fades in and scales up on open</li><li>No flicker, no flash of full opacity</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*iWsnRcgrIHc3pSSu.gif" /></figure><h4>📦 Compared to Old Methods</h4><p><strong>Before:</strong></p><pre>modal.classList.add(&#39;visible&#39;); // JS-based logic<br>setTimeout(() =&gt; modal.classList.add(&#39;animate-in&#39;), 10);</pre><p><strong>Now:</strong></p><pre>.modal:open {<br>  transition: all 0.3s ease;<br><br>  @starting-style {<br>    opacity: 0;<br>    transform: translateY(10px);<br>  }<br><br>  opacity: 1;<br>  transform: translateY(0);<br>}</pre><p>🧼 Result: No JavaScript hacks, better maintainability, and <strong>native animation behavior</strong>.</p><h3>💡 Best Practices</h3><ul><li>Use @starting-style when animating elements that appear dynamically (modals, tooltips, dropdowns, etc.)</li><li>Combine with transition for best results</li><li>Don’t overuse — keep animations subtle and purposeful</li><li>Use :open, :has(), or utility classes to trigger the state change</li><li>Like other modern CSS features, @starting-style is safe to use as <strong>progressive enhancement</strong>. It won’t break anything — the animation just won’t be as smooth in unsupported browsers.</li></ul><h3>🌀 6. offset-path — Animate along custom paths</h3><p>We’re used to animating elements along straight lines — translateX, translateY, maybe some easing. But what if you want an element to move <strong>along a curve</strong> or follow a <strong>custom shape</strong>?</p><p>With offset-path, that’s now possible — and it’s easier than you think.</p><h3>What Is offset-path?</h3><p>With offset-path, you can make an element move along a curve or a custom path – like a racetrack. And yes, it’s way easier than it sounds.</p><p>Think of it like setting a racetrack for an element, and then moving it from start to finish.</p><pre>.ball {<br>  offset-path: path(&#39;M0,0 C100,200 200,-100 300,0&#39;);<br>  animation: follow-path 4s linear infinite alternate;<br>}<br><br>@keyframes follow-path {<br>  0% {<br>    offset-distance: 0%;<br>    transform: rotate(0deg);<br>  }<br>  100% {<br>    offset-distance: 100%;<br>    transform: rotate(360deg);<br>  }<br>}</pre><p>✅ Smooth, natural motion. Super cool.</p><p>Creative use cases: icons following a path, objects moving in non-linear ways, hero section eye candy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*rmVOHEUmRYcE1AwM.gif" /></figure><h3>🧠 7. @property — Typed, animatable CSS variables</h3><p>Custom properties can now be <strong>typed</strong> and <strong>animated</strong>.</p><pre>@property --accent-color {<br>  syntax: &#39;&lt;color&gt;&#39;;<br>  inherits: false;<br>  initial-value: #ffcc00;<br>}<br><br>.button {<br>  background-color: var(--accent-color);<br>  transition: --accent-color 0.5s;<br>}<br><br>.button:hover {<br>  --accent-color: #ff6600;<br>}</pre><p>✅ Animating variables without JS? Yes, please.</p><p>🎨 Great for dynamic design systems and complex theme-based animations.</p><h3>🖼️ 8. image-set() — Finally, responsive images in CSS</h3><p>Choose the right image for each screen density:</p><pre>.hero {<br>  background-image: image-set(<br>    url(https://medium.com/&quot;img-lowres.jpg&quot;) 1x,<br>    url(https://medium.com/&quot;img-highres.jpg&quot;) 2x<br>  );<br>}</pre><p>✅ Better quality on retina displays without slowing everyone else down.</p><p><strong>📦 Optimizes image loading → less bandwidth, better performance, top-tier UX.</strong></p><h3>✒️ 9. text-wrap &amp; white-space-collapse — Typography control</h3><p>Typography is one of the most important — and often most overlooked — aspects of web design.</p><p>Good typography enhances <strong>readability</strong>, <strong>user experience</strong>, and <strong>visual appeal</strong>. And now, with modern CSS features like text-wrap and white-space-collapse, you can manage text flow with much more precision — <strong>without JavaScript tricks or weird layout hacks</strong>.</p><pre>h1 {<br>  text-wrap: balance;<br>}<br><br>.code-snippet {<br>  white-space-collapse: preserve-breaks;<br>}</pre><h3>1. text-wrap: balance – Perfectly Wrapped Headlines</h3><p>Normally, long headlines just break wherever the browser feels like it. The result? Uneven lines, awkward spacing, and a messy look — especially on mobile.</p><p>✅ Visually balanced titles<br>✅ Preformatted text that’s readable even in flexible layouts</p><p>Try text-wrap: balance on a long heading — you&#39;ll see a massive improvement in visual balance.</p><p>No more manually adding &lt;br&gt; tags or tweaking line breaks for each screen size. Let the browser do the work — and it does it well.</p><h3>2. white-space-collapse: preserve-breaks – Respect Line Breaks in Text</h3><p>Ever had to display preformatted content like:</p><ul><li>Code snippets</li><li>Poetry</li><li>ASCII art</li><li>Markdown blocks</li></ul><p>…but CSS just ignores the spacing or collapses your line breaks?</p><p>With white-space-collapse, you can control how line breaks and spaces are handled — more cleanly than older white-space: pre or pre-wrap tricks.</p><h3>🧩 10. Scroll-Linked Animations — Scroll-triggered effects</h3><p>With scroll-timeline, you can sync animations with scroll progress:</p><pre>.scroll-section {<br>  position: relative;<br>}<br><br>.scroll-section .container {<br>  max-width: 800px;<br>  margin: 0 auto;<br>  padding: clamp(1rem, 2vw, 5rem);<br>}<br><br>.scroll-section .progress {<br>  height: 1rem;<br>  background: rgb(131, 58, 180);<br>  background: linear-gradient(<br>    90deg,<br>    rgba(131, 58, 180, 1) 0%,<br>    rgba(253, 29, 29, 1) 50%,<br>    rgba(252, 176, 69, 1) 100%<br>  );<br>  position: fixed;<br>  top: 0;<br>  left: 0;<br>  width: 100%;<br>  transform-origin: 0 50%;<br>  animation: scaleProgress auto linear;<br>  animation-timeline: scroll(root);<br>  z-index: 9999;<br>}<br><br>@keyframes scaleProgress {<br>  0% {<br>    transform: scaleX(0);<br>  }<br>  100% {<br>    transform: scaleX(1);<br>  }<br>}<br><br><br><br>&lt;section class=&quot;scroll-section&quot;&gt;<br>  &lt;div class=&quot;progress&quot;&gt;&lt;/div&gt;<br>  &lt;div class=&quot;container&quot;&gt;<br>      .......<br>  &lt;/div&gt;<br>&lt;section</pre><p>✅ Scroll = animation. Like in the slickest modern sites.</p><p>🎯 Real use cases: scroll progress bars, cards that fade in as you scroll.</p><p><strong>Supported only in modern browsers (Chrome, Edge), but this is the future of interaction.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ktZhv06Gnovtj4Ye.gif" /></figure><h3>📦 Bonus Track: Container Queries — The next CSS revolution</h3><p>So far, responsive design has relied on <strong>media queries</strong>, which react to the <strong>viewport</strong>.</p><p>But what if your component lives in different layouts — inside a sidebar, or in a main content area?</p><p>With <strong>Container Queries</strong>, you can apply styles based on the <strong>container’s size</strong>, not the screen.</p><pre>.card {<br>  container-type: inline-size;<br>}<br><br>@container (min-width: 400px) {<br>  .card {<br>    flex-direction: row;<br>  }<br>}</pre><p>✅ When .card is wide enough, it switches layout.</p><p>📦 This makes components <strong>truly adaptive and reusable</strong>.</p><p>⚠️ <strong>Support in 2025:</strong></p><ul><li>Available in <strong>Chrome, Edge, Safari</strong></li><li>Experimental in other browsers (check caniuse.com)</li></ul><p>💡 Use them now? If your audience uses modern browsers, go for it. Otherwise, start designing with this in mind — it’s becoming the new standard.</p><h3>🔚 Conclusion</h3><p>CSS today is powerful, flexible, and smart.<br> If used well, it can replace tons of JavaScript and make your site:</p><p>⚡ Faster<br> 🧼 Cleaner<br> 🔩 More scalable</p><p>CSS in 2025 is no longer just a styling language: it’s a fundamental ally for building modern, fast, and scalable user interfaces. Embracing these new features means writing less JavaScript, achieving more performant sites, and creating richer and more engaging user experiences.</p><p>Which of these innovations excites you the most? Share your opinion in the comments!</p><p>🔗 <strong>See All the Examples in Action</strong></p><p>Want to play with all these features yourself?</p><p>👉 Check out the full set of live demos <a href="https://stackblitz.com/edit/future-of-css?file=styles.css">here</a> :)</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5b45170e62a" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-css-revolution-continues-10-modern-features-igniting-web-innovation-in-2025-bonus-track-c5b45170e62a">The CSS Revolution Continues: 10+ Modern Features Igniting Web Innovation in 2025 (+ bonus track)…</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Guide to Advanced Routing in Angular 19 (Mastering Angular Routing: From Basics to…]]></title>
            <link>https://javascript.plainenglish.io/the-ultimate-guide-to-advanced-routing-in-angular-19-mastering-angular-routing-from-basics-to-471d5fbb10b0?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/471d5fbb10b0</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[angular-19-new-features]]></category>
            <category><![CDATA[router]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 14:47:48 GMT</pubDate>
            <atom:updated>2025-04-02T16:45:44.118Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Guide to Advanced Routing in Angular 19 (Mastering Angular Routing: From Basics to Router Output Input and Providing Router) 🚦</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mM_S049nnKjUA2CF1pPj2Q.jpeg" /></figure><p>Routing in Angular is the core of Single Page Applications (SPA), allowing smooth and efficient transitions between different views. Angular 19 takes this functionality to the next level by providing powerful tools to manage navigation efficiently and scalably. In this article, we will explore advanced routing techniques, from basic configurations to sophisticated optimizations.</p><h3>Fundamentals of Routing in Angular 19</h3><p>Before diving into the complexities of advanced routing, it’s helpful to review the basics. With Angular 19, one key innovation is the ability to declare routes directly in the main module, eliminating the need for a separate routing module, as required in traditional approaches. This new feature simplifies routing configuration and streamlines the application initialization process.</p><h3>Routing Configuration</h3><p>In Angular 19, the routing configuration has been simplified by eliminating the need for AppRoutingModule. Routes can now be declared directly within the main module.</p><pre>import { bootstrapApplication } from &#39;@angular/platform-browser&#39;;<br>import { provideRouter, Routes } from &#39;@angular/router&#39;;<br>import { AppComponent } from &#39;./app/app.component&#39;;<br>import { HomeComponent } from &#39;./home/home.component&#39;;<br>import { AboutComponent } from &#39;./about/about.component&#39;;<br><br>const routes: Routes = [<br>  { path: &#39;&#39;, component: HomeComponent },<br>  { path: &#39;about&#39;, component: AboutComponent }<br>];<br><br>bootstrapApplication(AppComponent, {<br>  providers: [provideRouter(routes)]<br>});</pre><blockquote>❗ <strong>Note:</strong> This feature is supported only in Angular 19 and later; it is not backward compatible with older versions.</blockquote><h3>Advantages of provideRouter()</h3><p>Using provideRouter() instead of the traditional AppRoutingModule offers several benefits:</p><ul><li><strong>Simplified configuration</strong>: Routing is declared directly in the application bootstrap, removing the need for a separate module.</li><li><strong>Improved tree-shaking</strong>: Unnecessary dependencies are more easily removed from the final bundle, reducing the application size.</li><li><strong>Greater flexibility</strong>: Allows defining additional providers directly in the routing configuration, streamlining dependency management.</li></ul><h3>Router Features</h3><p>Angular 19 introduces RouterFeatures, a type alias representing all available router features that can be used with [provideRouter](https://angular.dev/api/router/provideRouter). These functions modify the router configuration during the bootstrap phase, enabling custom behaviors such as scroll strategies, URL management, and more.</p><p>Using RouterFeatures Example</p><pre>import { bootstrapApplication } from &#39;@angular/platform-browser&#39;;<br>import { provideRouter, Routes, withInMemoryScrolling, withQueryParamsHandling, withEnabledTracing } from &#39;@angular/router&#39;;<br>import { AppComponent } from &#39;./app/app.component&#39;;<br>import { HomeComponent } from &#39;./home/home.component&#39;;<br>import { AboutComponent } from &#39;./about/about.component&#39;;<br><br>const routes: Routes = [<br>  { path: &#39;&#39;, component: HomeComponent },<br>  { path: &#39;about&#39;, component: AboutComponent }<br>];<br><br>bootstrapApplication(AppComponent, {<br>  providers: [<br>    provideRouter(<br>      routes,<br>      withInMemoryScrolling({ scrollPositionRestoration: &#39;enabled&#39; }),<br>      withQueryParamsHandling({ strategy: &#39;merge&#39; }),<br>      withEnabledTracing()<br>    )<br>  ]<br>});</pre><h3>Explanation of RouterFeatures in the Example:</h3><ul><li>withInMemoryScrolling: Enables restoring scroll positions during navigation.</li><li>withQueryParamsHandling: Defines how query parameters are handled. The &#39;merge&#39; strategy combines new parameters with existing ones.</li><li>withEnabledTracing: Enables router tracing, useful for debugging by logging router activity in the browser console.</li></ul><h3><strong>✨ Key points about RouterFeatures:</strong></h3><h4>Extending Router Functionality:</h4><p>RouterFeaturesextend the basic routing capabilities, allowing developers to fine-tune navigation behaviors.</p><h4>Bootstrap Configuration:</h4><p>These features are applied during the application’s bootstrap process, ensuring they are active from the start.</p><h4>Integration</h4><p>RouterFeatures are used in combination with the provideRouter() function when setting up the application’s routing.<br>In essence, RouterFeaturesare a powerful tool in Angular 19 for fine-tuning the application’s routing to provide a better user experience and handle specific routing requirements.</p><h3>Router Outlet</h3><p>The &lt;router-outlet&gt; in the main template acts as a dynamic placeholder where routed components are displayed.</p><pre>&lt;nav&gt;<br>  &lt;a routerLink=&quot;/&quot;&gt;Home&lt;/a&gt;<br>  &lt;a routerLink=&quot;/about&quot;&gt;About&lt;/a&gt;<br>&lt;/nav&gt;<br>&lt;router-outlet&gt;&lt;/router-outlet&gt;</pre><h3>Router Link</h3><p>The routerLink directive creates navigable links, allowing users to move between views.</p><h3>Advanced Routing Techniques</h3><h4>Nested Routing (Child Routes)</h4><p>Nested routing allows for hierarchical route organization, useful for managing complex layouts.</p><pre>const routes: Routes = [<br>  { path: &#39;dashboard&#39;, component: DashboardComponent, children: [<br>    { path: &#39;profile&#39;, component: ProfileComponent },<br>    { path: &#39;settings&#39;, component: SettingsComponent }<br>  ]}<br>];</pre><h3>Lazy Loading</h3><p>Lazy loading improves performance by loading modules only when necessary.</p><pre>const routes: Routes = [<br>  { path: &#39;dashboard&#39;, loadChildren: () =&gt; import(&#39;./dashboard/dashboard.module&#39;).then(m =&gt; m.DashboardModule) }<br>];</pre><h3>Route Guards</h3><p>Route guards manage access to routes, enforcing authentication or other conditions before navigation.</p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { CanActivate } from &#39;@angular/router&#39;;<br>import { AuthService } from &#39;./auth.service&#39;;<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthGuard implements CanActivate {<br>  constructor(private authService: AuthService) {}<br>  canActivate(): boolean {<br>    return this.authService.isAuthenticated();<br>  }<br>}<br><br>const routes: Routes = [<br>  { path: &#39;admin&#39;, component: AdminComponent, canActivate: [AuthGuard] }<br>];</pre><h3>Route Resolvers</h3><p><em>Router resolvers</em> are another powerful advanced routing technique in Angular. They allow you to load the necessary data before the component is displayed, thus improving the user experience. With resolvers, you can load the required data (such as from an API) during the navigation phase, avoiding the display of a blank page or one with incomplete data. This approach is particularly useful for preventing noticeable delays in the user interface.</p><h4>How Route Resolvers Work:</h4><p>A resolver is a service that implements the `Resolve&lt;T&gt;` interface, which loads the data before the component is rendered. It is configured directly in the routes and allows passing the data to the component as part of the `ActivatedRoute` object.</p><h4>Benefits:</h4><ul><li>Preloads data before the component is rendered.</li><li>Improves the user experience by avoiding delays in loading.</li><li>Manages data loading logic centrally, separating it from the display logic.</li></ul><h3>Example of a Route Resolver</h3><pre>import { Injectable } from &#39;@angular/core&#39;;  <br>import { Resolve } from &#39;@angular/router&#39;;  <br>import { DataService } from &#39;./data.service&#39;;  <br>  <br>@Injectable({ providedIn: &#39;root&#39; })  <br>export class DataResolver implements Resolve&lt;any&gt; {  <br>  constructor(private dataService: DataService) {}  <br>  <br>  resolve() {  <br>    return this.dataService.getData();  <br>  }  <br>}  <br>  <br>const routes: Routes = [  <br>  {  <br>    path: &#39;dashboard&#39;,  <br>    component: DashboardComponent,  <br>    resolve: { data: DataResolver }  <br>  }  <br>];</pre><blockquote>This technique helps improve performance and ensures that the component is not rendered before the necessary data is available, increasing the reliability and smoothness of the application.</blockquote><h3>Introduction of Router Outlet Input in Angular 19</h3><p>Angular 19 introduces <strong>Router Outlet Input</strong>, a feature that allows passing data directly to components loaded via the router outlet, eliminating the need for intermediary services.</p><h3>Using Router Outlet Input</h3><p><em>Parent Component:</em></p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { Article } from &#39;./article.model&#39;;<br><br>@Component({<br>  selector: &#39;app-parent&#39;,<br>  template: `<br>    &lt;nav&gt;<br>      &lt;a routerLink=&quot;/&quot;&gt;Home&lt;/a&gt;<br>      &lt;a routerLink=&quot;/about&quot;&gt;About&lt;/a&gt;<br>    &lt;/nav&gt;<br>    &lt;!-- Passing data to the router outlet --&gt;<br>    &lt;router-outlet [routerOutletData]=&quot;articles&quot;&gt;&lt;/router-outlet&gt;<br>  `<br>})<br>export class ParentComponent {<br>  articles: Article[] = [<br>    { id: 1, title: &#39;Angular 19 Routing&#39;, content: &#39;Exploring new routing features in Angular 19&#39; },<br>    { id: 2, title: &#39;Router Outlet Input&#39;, content: &#39;Passing data directly to routed components&#39; }<br>  ];<br>}</pre><p><em>Child Routed Component:</em></p><pre>import { Component, inject } from &#39;@angular/core&#39;;<br>import { ROUTER_OUTLET_DATA } from &#39;@angular/router&#39;;<br>import { Article } from &#39;./article.model&#39;;<br><br>@Component({<br>  selector: &#39;app-routed&#39;,<br>  template: `<br>  @for (article of data; track article.id) {<br>    &lt;h2&gt;{{ article.title }}&lt;/h2&gt;<br>    &lt;p&gt;{{ article.content }}&lt;/p&gt;<br>  }<br>  `<br>})<br>export class RoutedComponent {<br>  data = inject(ROUTER_OUTLET_DATA) as Signal&lt;Article[]&gt;;<br>}</pre><p>In <strong>RoutedComponent</strong>, the data passed via <strong>[routerOutletData]</strong> in the parent component is retrieved using inject(ROUTER_OUTLET_DATA). This data is then used to populate the view in the child component. In this case, the array of articles is iterated, displaying <strong>the title</strong> and <strong>the content</strong> of each article.</p><h3>Optimizations and Best Practices</h3><ul><li>Organize routes into separate modules for better maintainability.</li><li>Use lazy loading to improve performance.</li><li>Implement route guards to protect sensitive sections.</li><li>Leverage route resolvers to preload necessary data.</li><li>Use route animations to enhance the user experience.</li><li>Choose the most suitable routing strategy for the project.</li></ul><h3>Conclusion</h3><p>Routing in Angular 19 is a powerful and flexible tool that allows developers to build sophisticated and high-performance SPA applications. By mastering the advanced techniques discussed in this article, you can create robust and scalable applications with an exceptional user experience.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=471d5fbb10b0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-ultimate-guide-to-advanced-routing-in-angular-19-mastering-angular-routing-from-basics-to-471d5fbb10b0">The Ultimate Guide to Advanced Routing in Angular 19 (Mastering Angular Routing: From Basics to…</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Multi-Language Without Libraries: A Custom Pipe with Signals ]]></title>
            <link>https://javascript.plainenglish.io/angular-multi-language-without-libraries-a-custom-pipe-with-signals-c1c18482fe77?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1c18482fe77</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[multilingual]]></category>
            <category><![CDATA[signal]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 15:51:41 GMT</pubDate>
            <atom:updated>2025-04-02T16:47:36.372Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DWbclF-zCAF7Zrz4KeWKxA.jpeg" /></figure><h3>Introduction</h3><p>When developing a multi-language application in Angular, one of the crucial aspects is managing translations efficiently. In this article, I will show you how to create a <strong>Pipe</strong> for dynamic translation that allows seamless and reactive language switching, leveraging the power of Angular Signals.</p><p><strong>Everything is managed entirely on the Frontend!</strong> We do not use external API calls to retrieve translations but store them directly in JSON files within the application. This ensures <strong>maximum speed and independence from the backend</strong>.</p><h3>Creating the Translation Pipe</h3><p><strong>Pipes</strong> in Angular are powerful tools for transforming data directly in templates. We will create a pipe called TranslatePipe that utilizes a <strong>translation service</strong> to return the translated value.</p><h3>Pipe Code</h3><pre>import { Pipe, PipeTransform } from &#39;@angular/core&#39;;<br>import { TranslationService } from &#39;../services/languageService.service&#39;;<br><br>@Pipe({<br>  name: &#39;translate&#39;,<br>  pure: false // Allows automatic recalculation when the language changes<br>})<br>export class TranslatePipe implements PipeTransform {<br>  constructor(private translationService: TranslationService) {}<br><br>  transform(value: string): string {<br>    return this.translationService.translate(value);<br>  }<br>}</pre><blockquote><strong>Why </strong><strong>pure: false?</strong> Setting this property ensures Angular re-executes the pipe whenever the language changes, preventing translation update issues in templates.</blockquote><h3>Implementing the Translation Service</h3><p>Now, let’s create a <strong>translation service</strong> that manages supported languages and provides the correct translation. All translations are <strong>loaded directly from the Frontend</strong>, with no need for API calls!</p><pre>import { computed, Injectable, Signal, signal } from &#39;@angular/core&#39;;<br>import * as en from &#39;../../../../src/assets/i18n/en.json&#39;;<br>import * as ita from &#39;../../../../src/assets/i18n/ita.json&#39;;<br><br>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class TranslationService {<br>  private language = signal&lt;&#39;ita&#39; | &#39;en&#39;&gt;(&#39;ita&#39;); // Default language<br><br>  private translations = computed(() =&gt; {<br>    return this.language() === &#39;ita&#39; ? ita : en;<br>  });<br><br>  setLanguage(lang: &#39;ita&#39; | &#39;en&#39;) {<br>    this.language.set(lang);<br>  }<br><br>  translate(key: string): string {<br>    const translations = this.translations() as Record&lt;string, string&gt;;<br>    return translations[key] || key;<br>  }<br>}</pre><blockquote><strong>Using Signals:</strong> We use signal and computed to ensure language changes automatically update translations <strong>without ever making HTTP requests</strong>.</blockquote><h3>Using It in a Template</h3><p>Now we can use the <strong>pipe</strong> directly in Angular templates.</p><pre>&lt;h1&gt;{{ &#39;HELLO&#39; | translate }}&lt;/h1&gt;<br>&lt;p&gt;{{ &#39;WELCOME&#39; | translate }}&lt;/p&gt;<br><br>&lt;!-- Buttons to change language --&gt;<br>&lt;button (click)=&quot;changeLang(&#39;ita&#39;)&quot;&gt;🇮🇹 Italiano&lt;/button&gt;<br>&lt;button (click)=&quot;changeLang(&#39;en&#39;)&quot;&gt;🇬🇧 English&lt;/button&gt;</pre><blockquote>When the user clicks a button, the application language changes, and texts update automatically <strong>without interacting with a backend</strong>.</blockquote><h3>Integrating into a Component</h3><p>Finally, let’s manage language switching within an Angular component.</p><pre>import { ChangeDetectorRef, Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import { TranslationService } from &#39;../services/languageService.service&#39;;<br><br>@Component({<br>  selector: &#39;app-dashboard&#39;,<br>  templateUrl: &#39;./dashboard.component.html&#39;,<br>  styleUrls: [&#39;./dashboard.component.scss&#39;]<br>})<br>export class DashboardComponent implements OnInit {<br>  translationService = inject(TranslationService);<br><br>  constructor(private cdr: ChangeDetectorRef) {<br>  }<br><br>  ngOnInit() {}<br><br>  changeLang(lang: &#39;ita&#39; | &#39;en&#39;) {<br>    this.translationService.setLanguage(lang);<br>    this.cdr.detectChanges();<br>  }<br>}</pre><blockquote><strong>We force change detection (</strong><strong>detectChanges)</strong> to ensure Angular updates the templates with the new language.</blockquote><h3>Conclusion</h3><p>We have created a <strong>dynamic translation pipe</strong> that leverages Signals to enable smooth and reactive language switching. <strong>All translations are managed entirely on the Frontend</strong>, avoiding API calls and improving performance.</p><p>✅ <strong>Advantages of this approach:</strong></p><ul><li>🚀 <strong>Zero HTTP calls:</strong> everything is handled locally</li><li>⚡ <strong>Instant language switching</strong> with no network delay</li><li>📂 <strong>Simple JSON file management</strong> directly in the project</li><li>🔧 <strong>Easy maintenance</strong> and scalability</li></ul><p>This approach is scalable, easy to maintain, and allows you to have a high-performance multi-language app without the need for external libraries like ngx-translate.</p><p>🔥 If you found this article useful, follow me for more insights on Angular and frontend development! 🚀</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1c18482fe77" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/angular-multi-language-without-libraries-a-custom-pipe-with-signals-c1c18482fe77">Angular Multi-Language Without Libraries: A Custom Pipe with Signals 🌍</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Surprising TypeScript Features You Probably Didn’t Know About]]></title>
            <link>https://javascript.plainenglish.io/5-surprising-typescript-features-you-probably-didnt-know-about-188f3574a832?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/188f3574a832</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Mon, 24 Mar 2025 13:56:13 GMT</pubDate>
            <atom:updated>2025-04-02T16:48:21.348Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aL-LQ0Md4FJ51486.png" /></figure><p>If you work with TypeScript, you’re probably familiar with its basic features like types, interfaces, and classes. But TypeScript is so much more, and in this article, I’ll explore some of its advanced and, at times, lesser-known features that could change the way you write your code.</p><h3>1. Mapped Types with as and keyof</h3><p>Imagine you want to create a new type based on the properties of another one. Mapped types let you do that easily. Using the keyof operator, you can extract all the keys from a type and use them to create a new one. A classic example is making all properties of an object readonly:</p><pre>type Person = {<br>  name: string;<br>  age: number;<br>};<br><br>type ReadonlyPerson = {<br>  readonly [K in keyof Person]: Person[K];<br>};<br><br>const person: ReadonlyPerson = { name: &#39;Karol&#39;, age: 30 };<br>// person.name = &#39;Ilenia&#39;; // Error, you can&#39;t modify a readonly value</pre><p>This syntax lets you manipulate types dynamically and powerfully without having to manually write everything out.</p><h3>2. as const for Immutable Literal Types</h3><p>When you use as const, TypeScript &quot;freezes&quot; the value, treating it as a specific literal type rather than a generic type. This is particularly useful when you have arrays or objects and want to prevent their values from being modified.</p><p>Here’s a practical example:</p><pre>const directions = [&quot;up&quot;, &quot;down&quot;, &quot;left&quot;, &quot;right&quot;] as const;<br><br>// ❌ Error! You cannot modify a value because it&#39;s readonly<br>// directions[0] = &quot;forward&quot;; <br><br>// ✅ TypeScript infers the exact type [&quot;up&quot;, &quot;down&quot;, &quot;left&quot;, &quot;right&quot;]<br>type Direction = typeof directions[number]; // &quot;up&quot; | &quot;down&quot; | &quot;left&quot; | &quot;right&quot;</pre><p>In this example, TypeScript automatically determines the return type of the MyFunction function without you having to explicitly write it out.</p><h3>4. Custom Utility Types with extends</h3><p>You’ve probably heard of utility types like Pick or Omit. But did you know you can create your own custom ones? By using the extends operator, you can define conditional types that let you manipulate your objects in a really flexible way.</p><p>For example, if you wanted to exclude a property from a type, you can do it easily:</p><pre>type ExcludeProperty&lt;T, K extends keyof T&gt; = Omit&lt;T, K&gt;;<br><br>type Person = { name: string; age: number; address: string };<br>type PersonWithoutAddress = ExcludeProperty&lt;Person, &#39;address&#39;&gt;;</pre><p>In this way, you get a new type that excludes the address property, making your code more reusable and less repetitive.</p><h3>5. Decorators for Adding Metadata</h3><p>Decorators are a powerful feature, albeit a bit more advanced, that lets you add metadata to classes, methods, or properties. Although they require enabling experimental decorators in your tsconfig.json, they’re extremely useful when working with frameworks that require a certain amount of metadata, such as Angular.</p><p>Here’s an example of how to use decorators to add some logic to your class:</p><pre>function log(target: any, key: string) {<br>  console.log(`${key} was accessed`);<br>}<br><br>class Person {<br>  @log<br>  name: string;<br>}<br><br>const p = new Person();<br>p.name = &#39;Ilenia&#39;;  // This will trigger the decorator and print &quot;name was accessed&quot;</pre><p>Decorators allow you to add behaviors at the class, property, or method level without directly modifying the code of these entities.</p><h3>Conclusion</h3><p>TypeScript is much more than just a JavaScript extension. With advanced features like mapped types, as const, infer, and decorators, you have powerful tools at your disposal to write more precise, secure, and reusable code. If you haven’t explored these yet, now is the perfect time to dive in!</p><p>If you found this article helpful or have other interesting TypeScript features to share, feel free to leave a comment below.</p><p>Happy coding! ✨</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=188f3574a832" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/5-surprising-typescript-features-you-probably-didnt-know-about-188f3574a832">5 Surprising TypeScript Features You Probably Didn’t Know About</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS view(): The Function That Revolutionizes Responsive Design ]]></title>
            <link>https://javascript.plainenglish.io/css-view-the-function-that-revolutionizes-responsive-design-429be8fa50a3?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/429be8fa50a3</guid>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Mon, 24 Mar 2025 11:41:28 GMT</pubDate>
            <atom:updated>2025-04-28T08:00:01.961Z</atom:updated>
            <content:encoded><![CDATA[<h3>CSS view(): The Future of Dynamic Animations 🚀</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*F5wvo8PzZlsfo-Ql.png" /></figure><h3>Introduction</h3><p>Responsive design has always required media queries, calc(), and dynamic units like vw and vh.<br> In recent years, clamp() has greatly simplified fluid layouts.<br> Now, there&#39;s a new function arriving for scroll-driven animations: view().</p><p>This intelligent function allows you to dynamically calculate element sizes <strong>based on the viewport and scroll position</strong>, opening new possibilities for animations.<br> Let’s see how it works and why you should start experimenting with it!</p><h3>What is view() and How Does It Work?</h3><p>The view() function is part of the new <strong>CSS Scroll-Linked Animations</strong> specification.<br> It allows you to define dynamic values during scroll animations, using three parameters:</p><pre>view(clamp, min_value, ideal_value, max_value)</pre><ul><li><strong>min_value</strong> → The smallest possible size</li><li><strong>ideal_value</strong> → The preferred size, based on the viewport</li><li><strong>max_value</strong> → The maximum allowed size</li></ul><p>The result? Elements that can <strong>animate smoothly during scrolling</strong>, adapting to the viewport size! 📱💻🖥️</p><blockquote>⚡ <em>Important:</em> For static responsive layouts (like resizing a box based on screen width), you should use clamp(), not view().<br> view() is specifically designed for scroll animations.</blockquote><h3>Practical Example: Scroll-Based Responsive Box (Experimental)</h3><p>Imagine animating a flexible box that resizes while scrolling.</p><h3>CSS + HTML Code</h3><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;CSS view() Demo&lt;/title&gt;<br>    &lt;style&gt;<br>        * {<br>            margin: 0;<br>            padding: 0;<br>            box-sizing: border-box;<br>            font-family: sans-serif;<br>        }<br><br>        body {<br>            display: flex;<br>            justify-content: center;<br>            align-items: center;<br>            height: 200vh; /* More scrollable area */<br>            background: #222;<br>            color: white;<br>            text-align: center;<br>        }<br><br>        .box {<br>            width: view(clamp, 150px, 50vw, 600px); /* Experimental scroll-linked size */<br>            height: view(clamp, 150px, 30vh, 400px);<br>            background: linear-gradient(135deg, #ff8a00, #e52e71);<br>            display: flex;<br>            justify-content: center;<br>            align-items: center;<br>            border-radius: 20px;<br>            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);<br>            transition: all 0.3s ease-in-out;<br>        }<br><br>        .box span {<br>            font-size: view(clamp, 1rem, 3vw, 2rem);<br>            font-weight: bold;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div class=&quot;box&quot;&gt;<br>        &lt;span&gt;Resize the window and scroll! 🎯&lt;/span&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Why is view() Revolutionary?</h3><p>✅ Enables scroll-driven animations with dynamic viewport-based values<br> ✅ Opens new creative possibilities without needing JavaScript<br> ✅ Allows smoother UX during scroll interactions<br> ✅ Prepares developers for the next generation of responsive animations</p><blockquote><em>📌 </em><strong><em>For traditional responsive layouts</em></strong><em> (without scrolling), use </em><em>clamp() to create fluid and adaptive designs.</em></blockquote><h3>Browser Compatibility</h3><p>As of now, view() is a relatively new feature and might not be <strong>fully supported</strong> across all browsers. It is currently in <strong>experimental stages</strong>, meaning that:</p><ul><li>✅ It works in the latest versions of Chromium-based browsers (Chrome, Edge, Opera)</li><li>⚠️ Partial support in Firefox (behind a flag in about:config)</li><li>❌ Not yet available in Safari and older browsers</li></ul><h3>How to Check Compatibility?</h3><p>Before using view() in production, always verify support using <a href="https://caniuse.com/">Can I Use</a> or by applying <strong>feature detection</strong> with CSS @supports:</p><pre>@supports (width: view(clamp, 100px, 50vw, 500px)) {<br>    .box {<br>        width: view(clamp, 100px, 50vw, 500px);<br>    }<br>}</pre><p>If not supported, you can always provide a <strong>fallback</strong> using clamp() or fixed units.</p><h3>Conclusion</h3><p>The view() function is an exciting addition for scroll-based animations, offering new ways to make designs react fluidly to user interactions.<br> While it’s still experimental, starting to experiment with it now will prepare you for the future of CSS animations!</p><p>For creating static, fluid layouts across devices, remember to rely on the well-supported and powerful clamp() function. 🚀</p><h3>🔥 Final Tip</h3><p>You can combine clamp() for layout sizing and view() for scroll-based dynamic effects — creating truly next-generation responsive experiences!</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=429be8fa50a3" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/css-view-the-function-that-revolutionizes-responsive-design-429be8fa50a3">CSS view(): The Function That Revolutionizes Responsive Design 🚀</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Unlock the Power of linkedSignal and resource: The Future of State Management in Angular! ]]></title>
            <link>https://javascript.plainenglish.io/linkedsignal-and-resource-in-angular-dac7bf2bdd8c?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dac7bf2bdd8c</guid>
            <category><![CDATA[resources]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[signal]]></category>
            <category><![CDATA[angular-19]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Fri, 14 Mar 2025 17:12:59 GMT</pubDate>
            <atom:updated>2025-04-24T10:59:35.114Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znyk3AAHypIntGEPEcggrg.jpeg" /></figure><p>With the latest updates in Angular, more advanced features for managing reactive state have been introduced. Among these, two of the most powerful and interesting ones are linkedSignal and resource. If you work with Angular and want to improve state management and asynchronous requests in your project, this guide is for you!</p><h3>What is linkedSignal?</h3><p>linkedSignal is a function that allows you to create a reactive state that depends on another state while maintaining an intelligent update logic.</p><h3>When to use it?</h3><ul><li>When you have a derived state that needs to be automatically updated based on another state.</li><li>When you want to avoid unnecessary side effects while keeping a consistent value.</li></ul><h3>Example: Selecting a product category</h3><p>Imagine having a list of product categories and wanting the selection to update automatically if the list changes.</p><pre>import { Component, signal, linkedSignal } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-category-picker&#39;,<br>  template: `<br>    &lt;select (change)=&quot;changeCategory($event.target.value)&quot;&gt;<br>      @for (let category of categories()) {<br>        &lt;option [value]=&quot;category&quot; [selected]=&quot;category === selectedCategory()&quot;&gt;<br>          {{ category }}<br>        &lt;/option&gt;<br>      }<br>    &lt;/select&gt;<br>    &lt;p&gt;Selected Category: {{ selectedCategory() }}&lt;/p&gt;<br>  `<br>})<br>export class CategoryPickerComponent {<br>  categories = signal([&#39;Electronics&#39;, &#39;Books&#39;, &#39;Clothing&#39;]);<br>  <br>  selectedCategory = linkedSignal({<br>    source: this.categories,<br>    computation: (newCategories, previous) =&gt; {<br>      return newCategories.includes(previous?.value) ? previous.value : newCategories[0];<br>    }<br>  });<br><br>  changeCategory(newCategory: string) {<br>    this.selectedCategory.set(newCategory);<br>  }<br>}</pre><h3>What happens?</h3><ul><li>If the user changes the category, the value updates.</li><li>If the list changes and the selected category still exists, it is retained.</li><li>If the selected category is no longer available, the first one in the list is chosen.</li></ul><h3>What is resource?</h3><p>resource is a function designed to handle asynchronous data, such as API calls, in a reactive and optimized way.</p><h3>When to use it?</h3><ul><li>When you need to fetch data from a server and want seamless integration with Signals.</li><li>When you want to effectively manage different loading states (loading, success, error).</li></ul><h3>Example: Loading user data based on ID</h3><p>Imagine needing to fetch user details whenever their ID changes.</p><pre>import { Component, signal, resource } from &#39;@angular/core&#39;;<br><br>interface User {<br>  id: number;<br>  name: string;<br>  email: string;<br>}<br><br>async function fetchUser(request: { id: number }): Promise&lt;User&gt; {<br>  const response = await fetch(`https://api.example.com/users/${request.id}`);<br>  return response.json();<br>}<br><br>@Component({<br>  selector: &#39;app-user-profile&#39;,<br>  template: `<br>    &lt;input type=&quot;number&quot; [value]=&quot;userId()&quot; (input)=&quot;changeUserId($event.target.value)&quot;&gt;<br>    @if (userResource.isLoading()) {<br>      &lt;p&gt;Loading...&lt;/p&gt;<br>    }<br>    @if (userResource.error()) {<br>      &lt;p&gt;Error loading data.&lt;/p&gt;<br>    }<br>    @if (userResource.hasValue()) {<br>      &lt;div&gt;<br>        &lt;h3&gt;{{ userResource.value().name }}&lt;/h3&gt;<br>        &lt;p&gt;Email: {{ userResource.value().email }}&lt;/p&gt;<br>      &lt;/div&gt;<br>    }<br>  `<br>})<br>export class UserProfileComponent {<br>  userId = signal(1);<br><br>  userResource = resource({<br>    request: () =&gt; ({ id: this.userId() }),<br>    loader: ({ request }) =&gt; fetchUser(request),<br>  });<br><br>  changeUserId(newId: string) {<br>    this.userId.set(Number(newId));<br>  }<br>}</pre><h3>What happens?</h3><ul><li>Whenever userId changes, an API request is made.</li><li>The system displays “Loading…” during the request.</li><li>If the request fails, an error message appears.</li><li>If the request is successful, the user’s name and email are displayed.</li></ul><h3>Conclusion</h3><p>Angular is evolving with increasingly powerful tools for state management and asynchronous operations.</p><ul><li>Use <strong>linkedSignal</strong> when you have a state that depends on another and want to keep it consistent without side effects.</li><li>Use <strong>resource</strong> when you need to efficiently manage asynchronous data in a reactive way.</li></ul><p>These new features make Angular development more reactive and intuitive, improving both code writing and user experience!</p><p>If you found this guide helpful, share it and leave a comment with your experiences! 🚀</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dac7bf2bdd8c" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/linkedsignal-and-resource-in-angular-dac7bf2bdd8c">🔥 Unlock the Power of linkedSignal and resource: The Future of State Management in Angular! 🚀</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Experiment: Angular 19 without zone.js, lazy loading app in a web component with angular element ]]></title>
            <link>https://javascript.plainenglish.io/goodbye-zone-js-f7a2fddcb214?source=rss-ef6855d6613d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7a2fddcb214</guid>
            <category><![CDATA[zoneless]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Ilenia Scala]]></dc:creator>
            <pubDate>Fri, 14 Mar 2025 15:36:51 GMT</pubDate>
            <atom:updated>2025-04-24T10:59:41.952Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mxHHqKR5DQx6HHTwNKqCLA.jpeg" /></figure><h3>Introduction</h3><p>In the world of modern web development, performance is a crucial aspect. When I started working on a new project in Angular 19, I decided to take on an interesting challenge: <strong>building an app without using Zone.js, implementing lazy loading to optimize resource loading, and finally turning it into a Web Component</strong> to make it reusable everywhere. In this article, I will guide you through my process, the challenges I encountered, and the results I achieved.</p><p><strong>What is Angular without Zone.js?</strong><br> By default, Angular uses Zone.js to handle change detection and efficiently update the view. However, sometimes Zone.js can become a bottleneck, especially in large applications or scenarios where reactivity is not necessary.</p><p><strong>Why remove Zone.js?</strong><br> Deciding to disable Zone.js in Angular helps reduce the overhead of change detection operations, thereby improving performance. Without Zone.js, you will need to manually handle change detection, but this gives you finer control over the application’s behavior and can result in a better user experience, especially in high-performance application scenarios.</p><h3>Implementation</h3><p><strong>How to Create and Build an Angular App Without Zone.js</strong><br> A key part of my project was configuring Angular without Zone.js. Fortunately, Angular 19 supports a zoneless mode through the --experimental-zoneless option. This approach allows you to disable Zone.js and further optimize the app&#39;s performance.</p><p><strong>Create the Angular Project Without Zone.js</strong><br> To create a new Angular application without Zone.js, you can use the npx command to get the latest version of Angular CLI with the --experimental-zoneless flag:</p><pre>npx -p @angular/cli@latest ng new [project_name] --experimental-zoneless</pre><p><strong>Remove the Zone.js Dependency</strong><br>First, you need to remove the zone.js dependency from the package.json file. You can do this by using the npm command to uninstall zone.js:</p><pre>npm uninstall zone.js</pre><p><strong>Configuring the Application Without Zone.js Using provideExperimentalZonelessChangeDetection</strong></p><p>Once the project is created without Zone.js, it’s important to configure the application so that Angular works correctly without the automatic change detection of Zone.js. To do this, we use the provideExperimentalZonelessChangeDetection provider within the app&#39;s configuration file (e.g., app.config.ts or a similar file).</p><p>Here’s how to properly configure the application:</p><pre>import { ApplicationConfig, provideExperimentalZonelessChangeDetection } from &#39;@angular/core&#39;;<br>import { provideRouter } from &#39;@angular/router&#39;;<br>import { routes } from &#39;./app.routes&#39;;<br>import { provideHttpClient } from &#39;@angular/common/http&#39;;<br><br>export const appConfig: ApplicationConfig = {<br>  providers: [<br>    provideExperimentalZonelessChangeDetection(),  // Enables change detection without Zone.js<br>    provideRouter(routes),  // Provides the router configuration<br>    provideHttpClient()     // Provides the HTTP client<br>  ]<br>};</pre><p>Configuring an Angular application without Zone.js requires the use of provideExperimentalZonelessChangeDetection to manage the change detection cycle manually, along with the traditional provideRouter to handle navigation. These two providers allow the application to function correctly without Zone.js, improving performance while maintaining precise management of the application’s lifecycle.</p><p><strong>Using ChangeDetectionStrategy.OnPush in Components</strong><br> In Angular, ChangeDetectionStrategy.OnPush is a strategy that optimizes change detection in components. Instead of monitoring every change during each cycle, Angular checks only when:</p><ul><li>The component’s inputs change.</li><li>An event is emitted by the component (e.g., a click).</li></ul><p><strong>How to Use It</strong><br> To configure a component with OnPush, set the changeDetection property in the component&#39;s decorator:</p><pre>@Component({<br>  selector: &#39;app-my-component&#39;,<br>  templateUrl: &#39;./my-component.component.html&#39;,<br>  changeDetection: ChangeDetectionStrategy.OnPush<br>})<br>export class MyComponent {<br>  data: string = &#39;Hello, world!&#39;;<br>}</pre><p><strong>Managing Changes Without Zone.js</strong><br> <strong>Detection with Inputs</strong>: Angular detects changes when the inputs change.</p><p><strong>Forcing Detection</strong>: Use ChangeDetectorRef to manually trigger change detection:</p><pre>constructor(private cdRef: ChangeDetectorRef) {}<br>triggerChangeDetection() {<br>  this.cdRef.detectChanges();<br>}</pre><p><strong>Creating a Web Component with Angular</strong><br> To transform an Angular app into a Web Component, follow these steps:</p><p><strong>Install @angular/elements</strong><br> First, you need to install the @angular/elements package, which allows you to create Web Components in Angular:</p><pre>npm install @angular/elements</pre><p><strong>Create a Wrapper Component</strong><br> To create a Web Component, a wrapper component is required to encapsulate the entire application. This component will not only export Angular logic as a Web Component but is also essential for preserving router functionality, which is managed in the AppComponent.</p><p>In the wrapper component, we can keep the routing and other Angular features without modifying them. The AppComponent will remain the heart of the application, but it will be &quot;encapsulated&quot; within the wrapper, which will become the final Web Component.</p><p>Example of a wrapper component:</p><pre>import { Component, Injector, NgModule } from &#39;@angular/core&#39;;<br>import { createCustomElement } from &#39;@angular/elements&#39;;<br>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { AppComponent } from &#39;./app.component&#39;;<br>import { provideRouter } from &#39;@angular/router&#39;;<br>import { routes } from &#39;./app.routes&#39;;<br><br>@Component({<br>  selector: &#39;app-wrapper&#39;,<br>  template: &#39;&lt;app-root&gt;&lt;/app-root&gt;&#39;<br>})<br>export class WrapperComponent {}</pre><p>In this way, AppComponent maintains control over routing and application logic, while the WrapperComponent becomes the Web Component that you export.</p><p><strong>Modify the Bootstrap</strong><br> In the main.ts file, instead of bootstrapping the AppComponent, bootstrap the WrapperComponent and register it as a Web Component:</p><pre>import { platformBrowserDynamic } from &#39;@angular/platform-browser-dynamic&#39;;<br>import { WrapperComponent } from &#39;./wrapper.component&#39;;<br>import { AppModule } from &#39;./app.module&#39;;<br>import { createCustomElement } from &#39;@angular/elements&#39;;<br><br>const wrapper = createCustomElement(WrapperComponent, { injector: this.injector });<br><br>customElements.define(&#39;my-web-component&#39;, wrapper);<br><br>platformBrowserDynamic().bootstrapModule(AppModule)<br>  .catch(err =&gt; console.error(err));</pre><p>Insert &lt;my-web-component&gt;&lt;/my-web-component&gt; instead of &lt;app-root&gt; in index.html</p><pre>&lt;!-- index.html --&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;<br>    &lt;title&gt;Angular Web Component&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;my-web-component&gt;&lt;/my-web-component&gt; &lt;!-- Use the custom web component --&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>✨ Conclusion</strong><br>With these steps, your Angular project is ready to be transformed into a Web Component. The application is encapsulated within the wrapper and exported as a Web Component using @angular/elements. You can now use the custom component in any other project or framework.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7a2fddcb214" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/goodbye-zone-js-f7a2fddcb214">Experiment: Angular 19 without zone.js, lazy loading app in a web component with angular element 🚀</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>