<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bishal Pahari</title>
    <description>The latest articles on DEV Community by Bishal Pahari (@bishalpahari).</description>
    <link>https://dev.to/bishalpahari</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1036061%2Fce3f5d1f-e9c7-420b-9162-340b3da9ddbd.jpeg</url>
      <title>DEV Community: Bishal Pahari</title>
      <link>https://dev.to/bishalpahari</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bishalpahari"/>
    <language>en</language>
    <item>
      <title>Shipping a web app as a Flutter app's UI, with signed over-the-air updates</title>
      <dc:creator>Bishal Pahari</dc:creator>
      <pubDate>Mon, 23 Nov 2026 14:19:58 +0000</pubDate>
      <link>https://dev.to/bishalpahari/shipping-a-web-app-as-a-flutter-apps-ui-with-signed-over-the-air-updates-e5c</link>
      <guid>https://dev.to/bishalpahari/shipping-a-web-app-as-a-flutter-apps-ui-with-signed-over-the-air-updates-e5c</guid>
      <description>&lt;p&gt;I build for the web. Every time a product I worked on needed a phone app, the same two problems came back: the UI got written twice, and a one-word copy fix waited days for store review.&lt;/p&gt;

&lt;p&gt;Valence is the setup I wanted for that: your existing web app becomes the UI of a small Flutter app, and UI changes ship over the air as signed bundles. It's open source (MIT) and the first public beta, 0.4.0-beta.1, is out now.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A small Flutter host ships through the stores once.&lt;/strong&gt; It's a normal Flutter app that depends on the &lt;a href="https://pub.dev/packages/valence" rel="noopener noreferrer"&gt;&lt;code&gt;valence&lt;/code&gt;&lt;/a&gt; package. Its &lt;code&gt;main.dart&lt;/code&gt; is about twenty lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your web app is the UI.&lt;/strong&gt; SvelteKit, Vite, Astro or a Next.js static export, built to static files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Each release is a signed bundle.&lt;/strong&gt; The CLI hashes every file, signs the manifest with an Ed25519 key, and you upload it to any static host.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Each phone checks it before using it.&lt;/strong&gt; It verifies the signature and every file's hash, serves the bundle to a WebView from a local loopback server, and runs it as a trial.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bad releases roll themselves back.&lt;/strong&gt; If the new UI doesn't call &lt;code&gt;ready()&lt;/code&gt; within its time limit twice, the phone marks it bad and goes back to the last good bundle. No server-side monitoring is involved.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The host side really is short:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="nc"&gt;Future&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;valence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Valence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;valenceConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hostBuild&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;handlers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AppHandlers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;valence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;runApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MaterialApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ValenceApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;valence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;valence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;bridgeDispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handlers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A release is three commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run build                                          &lt;span class="c"&gt;# your web app, as usual&lt;/span&gt;
node valence/valence.mjs bundle                        &lt;span class="c"&gt;# hash, sign, write the manifest&lt;/span&gt;
node valence/valence.mjs pointer --channel production --rollout 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--rollout 10&lt;/code&gt; sends it to 10% of phones first. You raise it to 50 and 100 by updating a small pointer file; nothing is re-signed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data that works offline
&lt;/h2&gt;

&lt;p&gt;App data lives in SQLite on the phone, not in the WebView's storage. A first launch in airplane mode shows real content because the app ships with a seed. Writes go to an outbox and sync when the phone is back online, and reads sync incrementally ("everything after update #1234"). You bring your own backend and login; the host keeps the token in the Android Keystore.&lt;/p&gt;

&lt;p&gt;The bridge between the page and the native side is generated from one schema file into both TypeScript and Dart, so the two sides can't drift apart. Add a method to the schema, run codegen, and the Dart analyzer tells you exactly which handler you still have to write.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the docs like a stranger would
&lt;/h2&gt;

&lt;p&gt;Before announcing it, I had two coding agents build a small offline grocery-list app overnight. Their only sources were the public docs and the published packages; reading the Valence source was off-limits. They logged every place they got stuck.&lt;/p&gt;

&lt;p&gt;They found 14 problems. The worst: a brand-new project's first Android build failed with an error about &lt;code&gt;flutter_local_notifications&lt;/code&gt;, a plugin the developer never added. Others were quieter, like a doctor check that asked for files the docs never mentioned, or a deep-link edge case where the Android back gesture leaves the app.&lt;/p&gt;

&lt;p&gt;0.4.0-beta.1 fixes all of them, and re-running the same flow on a fresh project found three more, which are fixed too. That friction log turned out to be the most useful testing I've done.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it isn't yet
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;iOS is experimental and untested.&lt;/strong&gt; Android is the supported platform.&lt;/li&gt;
&lt;li&gt;On Android, if the system kills the WebView's renderer under memory pressure, the app closes. Your data is safe, and the docs explain how to spot it, but it's a reason to start rollouts small.&lt;/li&gt;
&lt;li&gt;Store rules allow downloaded JavaScript that runs in a WebView as long as the app's purpose doesn't change. The docs quote the Apple and Google wording this relies on, but reviewers judge each app, so treat that as a reason for care, not a guarantee.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;In your web project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create valence@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then follow the &lt;a href="https://getvalence.dev/docs/getting-started/quick-start/" rel="noopener noreferrer"&gt;quick start&lt;/a&gt;. The code and the full spec are on &lt;a href="https://github.com/valence-dev/valence" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you try it, I'd like to hear where it got in your way. Those reports are what the next release is built from.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>webdev</category>
      <category>opensource</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Recreating Ambient Mode from Youtube Videos</title>
      <dc:creator>Bishal Pahari</dc:creator>
      <pubDate>Sat, 01 Mar 2025 04:16:38 +0000</pubDate>
      <link>https://dev.to/bishalpahari/recreating-ambient-mode-from-youtube-videos-5f75</link>
      <guid>https://dev.to/bishalpahari/recreating-ambient-mode-from-youtube-videos-5f75</guid>
      <description>&lt;h2&gt;
  
  
  Briefly About Ambient Mode
&lt;/h2&gt;

&lt;p&gt;In October 2022, YouTube introduced Ambient Mode, an immersive feature that enhances the viewing experience by extending the video's colors into the interface background. This effect, available exclusively in Dark Mode, reduces eye strain and adds a cinematic touch to video playback. &lt;/p&gt;

&lt;p&gt;In this blog, we'll create a dynamic ambient mode similar to YouTube's Ambient Mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by Step Guide
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;It's essentially two different stacked videos playing in sync with effects.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34db9i39rpa05q1p5psr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34db9i39rpa05q1p5psr.png" alt=" " width="290" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, wrap two &lt;code&gt;video&lt;/code&gt; elements within a &lt;code&gt;div.container&lt;/code&gt;. Here, we'll use the first &lt;code&gt;video&lt;/code&gt; element for the ambient mode and the second as our main video. Ensure you mute and remove the controls of the ambient &lt;code&gt;video&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7qfp3c1yr9j7q0qp9gm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7qfp3c1yr9j7q0qp9gm.png" alt=" " width="299" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzgml9mwr0htacgj5sday.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzgml9mwr0htacgj5sday.png" alt=" " width="362" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, set the container's position to &lt;code&gt;relative&lt;/code&gt; and the second video's position to &lt;code&gt;absolute&lt;/code&gt;, positioning the main video over the ambient one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsowkrztcbesetc5qn9jo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsowkrztcbesetc5qn9jo.png" alt=" " width="354" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this stage, your setup should look similar to the picture above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjeeuvks4zxa8yhwgvjhn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjeeuvks4zxa8yhwgvjhn.png" alt=" " width="338" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, scale up the ambient mode video element so it expands and becomes visible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz4khc6bqjmj9m830qyp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz4khc6bqjmj9m830qyp.png" alt=" " width="338" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add some blur to the ambient mode &lt;code&gt;video&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filvan649eb29tq8cwyu4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filvan649eb29tq8cwyu4.png" alt=" " width="332" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, reduce the opacity of the ambient mode video element to enhance the effect.&lt;/p&gt;

&lt;p&gt;If you want to create a dynamic ambient mode that syncs with the main video, you can achieve this using JavaScript. Configure actions so that the main video's controls also affect the ambient mode video.&lt;/p&gt;

&lt;p&gt;Thanks for following along! I hope you found this guide helpful and easy to understand. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Youtube blog:&lt;/strong&gt; &lt;a href="https://support.google.com/youtube/answer/12827017?hl=en&amp;amp;co=GENIE.Platform%3DAndroid" rel="noopener noreferrer"&gt;Open (Watch YouTube in ambient mode)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo Site:&lt;/strong&gt; &lt;a href="https://youtube-ambient-demo.netlify.app/" rel="noopener noreferrer"&gt;Youtube-ambient-mode&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code:&lt;/strong&gt; &lt;a href="https://github.com/Bishal-Pahari/Youtube-ambient-mode" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>The Magical effect Behind the KPR Verse Footer Effect</title>
      <dc:creator>Bishal Pahari</dc:creator>
      <pubDate>Wed, 09 Oct 2024 03:48:12 +0000</pubDate>
      <link>https://dev.to/bishalpahari/unraveling-the-magical-effect-behind-the-kpr-verse-footer-effect-42bm</link>
      <guid>https://dev.to/bishalpahari/unraveling-the-magical-effect-behind-the-kpr-verse-footer-effect-42bm</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnccc4u2rflvu1nd0h64.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnccc4u2rflvu1nd0h64.gif" alt="KPR Verse" width="600" height="287"&gt;&lt;/a&gt;&lt;br&gt;
I was scrolling through the KPR-verse website when I noticed this cool effect at the bottom. Whenever I see something like this, I always want to recreate it. My process is simple: I start by trying to replicate the effect, then make a blog to explain how it’s done, aiming to break down complex designs into easy-to-understand steps.&lt;/p&gt;

&lt;p&gt;At first, I often doubt whether I can pull it off, but after some deep thought, I usually find a way to break the design into pieces. By connecting those pieces, I manage to achieve the effect. Enough talk — let’s dive into how you can make it yourself!&lt;/p&gt;

&lt;h2&gt;
  
  
  Breaking Down the KPR Verse Footer Effect
&lt;/h2&gt;

&lt;p&gt;At the end of the site, you’ll find the KPR banner in the background. At first glance, it might seem a bit complex, but it’s not that complicated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5pr9dq6lqh4k5idfkkb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5pr9dq6lqh4k5idfkkb.png" alt="Step 1" width="357" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, create a &lt;code&gt;div&lt;/code&gt; with the class &lt;code&gt;.container&lt;/code&gt;. This will be the root element for our tutorial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8699ztgp5nf78vab6vq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8699ztgp5nf78vab6vq.png" alt="Step 2" width="386" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, divide the .container into two parts: &lt;code&gt;.subcontainer-wrapper&lt;/code&gt; and &lt;code&gt;footer&lt;/code&gt;. The &lt;code&gt;footer&lt;/code&gt; element will hold the KPR banner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj05u7ujiis9i64upbwht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj05u7ujiis9i64upbwht.png" alt="Step 3" width="800" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, further divide the &lt;code&gt;.subcontainer-wrapper&lt;/code&gt; into two parts. The upper part contains all the content for our website, while the lower part is left blank with no background—essentially invisible, but it still has the width and height of the viewport. The lower half is crucial because it allows us to see the footer.&lt;/p&gt;

&lt;p&gt;Up to this point, all the elements are in the normal HTML flow, i.e., top-to-bottom. Now, we need to break this order by placing the footer behind and bringing the &lt;code&gt;.subcontainer-wrapper&lt;/code&gt; in front. To do this, we'll set the &lt;code&gt;.subcontainer-wrapper&lt;/code&gt; to position: absolute relative to its parent .container. This will remove the &lt;code&gt;.subcontainer-wrapper&lt;/code&gt; from the normal DOM flow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplh0d63s5o9yty5j34hf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplh0d63s5o9yty5j34hf.png" alt="Step 4" width="517" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all we need to set up the effect. Now, fill the upper part of the &lt;code&gt;.subcontainer-wrapper&lt;/code&gt; with content, but leave the lower part—the invisible div—empty. Also, add content to the footer.&lt;/p&gt;

&lt;p&gt;Once you’ve added the content, it should look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8tfx9sdp6stxe40nlhy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8tfx9sdp6stxe40nlhy9.png" alt="Step 5" width="656" height="596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The upper part hides the background, and as you scroll down, when the visible content ends, the invisible section reveals the footer. Voilà! There you have it — simple and easy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1ti5kh57c2msx0cv3ee.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1ti5kh57c2msx0cv3ee.png" alt="Step 6" width="626" height="638"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;_Thanks for following along! I hope you found this guide helpful and easy to understand. Stay curious and keep exploring!&lt;/p&gt;

&lt;p&gt;original: &lt;a href="https://kprverse.com/" rel="noopener noreferrer"&gt;KPR-verse&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Demo site: &lt;a href="https://kprverse-demo.netlify.app/" rel="noopener noreferrer"&gt;Demo Link&lt;/a&gt; , For this demonstration, I used the Google I/O site (&lt;a href="https://io.google/2024/" rel="noopener noreferrer"&gt;https://io.google/2024/&lt;/a&gt;) and adapted it to showcase a similar concept.&lt;/p&gt;

&lt;p&gt;Source code: &lt;a href="https://github.com/Bishal-Pahari/KPR-verse-Footer" rel="noopener noreferrer"&gt;Github Link&lt;/a&gt;_&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
      <category>frontendchallenge</category>
    </item>
    <item>
      <title>iOS-Style Switch Button: A Simple Step-by-Step Guide</title>
      <dc:creator>Bishal Pahari</dc:creator>
      <pubDate>Sat, 16 Mar 2024 07:37:50 +0000</pubDate>
      <link>https://dev.to/bishalpahari/crafting-an-ios-style-switch-button-a-simple-step-by-step-guide-5ii</link>
      <guid>https://dev.to/bishalpahari/crafting-an-ios-style-switch-button-a-simple-step-by-step-guide-5ii</guid>
      <description>&lt;p&gt;Have you ever wanted to create an iOS-style switch button for your web apps? No need to be an expert! Let’s create one together using HTML, CSS, and JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxm6w04djqt32yulrlf7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxm6w04djqt32yulrlf7t.png" alt="iOS switch Button" width="313" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of HTML, CSS, and JavaScript.&lt;/li&gt;
&lt;li&gt;A text editor of your choice.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let’s deep dive into the code&lt;/strong&gt;&lt;br&gt;
Create a new file named &lt;code&gt;index.html&lt;/code&gt; within your project folder and add the following HTML code:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;index.html&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;IOS Button&amp;lt;/title&amp;gt;

    &amp;lt;!-- Link to the external CSS file for styling --&amp;gt;
    &amp;lt;link rel="stylesheet" href="./styles.css" /&amp;gt;

    &amp;lt;!-- Link to the external JavaScript file for functionality --&amp;gt;
    &amp;lt;script defer src="./main.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;!-- Container for the switch button --&amp;gt;
    &amp;lt;div class="switch-container"&amp;gt;

      &amp;lt;!-- Box containing the image and text --&amp;gt;
      &amp;lt;div class="pack-box"&amp;gt;
        &amp;lt;!-- Image for the switch button --&amp;gt;
        &amp;lt;img id="svg-icon" src="./active.svg" /&amp;gt;
        &amp;lt;!-- Text for the switch button --&amp;gt;
        &amp;lt;p&amp;gt;Notification Alert&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;!-- Label associating the input with the switch functionality --&amp;gt;
      &amp;lt;label for="switch-1" class="switch"&amp;gt;
        &amp;lt;!-- Input checkbox acting as the switch button --&amp;gt;
        &amp;lt;input type="checkbox" id="switch-1" onClick="handleChange()" /&amp;gt;
        &amp;lt;!-- Span element creating the appearance of the slider button --&amp;gt;
        &amp;lt;span class="slider"&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;/label&amp;gt;

    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I’ve structured the content to include a switch container &lt;code&gt;.switch-container&lt;/code&gt; housing a pack box &lt;code&gt;.pack-box&lt;/code&gt; holding an image &lt;code&gt;.svg-icon&lt;/code&gt; and text "Notification Alert". A label &lt;code&gt;.switch&lt;/code&gt; is associated with a checkbox input &lt;code&gt;.switch-1&lt;/code&gt; and a span &lt;code&gt;.slider&lt;/code&gt; to create the appearance of a slider button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfxlesi8cpw5ji6abhfv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfxlesi8cpw5ji6abhfv.png" alt="HTML Element visualization" width="800" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Styling the Switch Button with CSS&lt;/strong&gt;&lt;br&gt;
To style the switch button, create a file named styles.css and link it to your HTML file. Begin by ensuring proper alignment and centering of elements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Centering body content */ 
body {
  height: 100dvh;
  width: 100dvw;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Styling container */ 
.switch-container {
  width: 300px;
  height: 150px;
  border: 3px solid #636363;
  border-radius: 25px 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
}


.switch-container img {
  width: 25px;
}

/* Styling box with image and text */
.pack-box {
  display: flex;
  gap: 1rem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moving to the main logic for the switch button styling, we define its dimensions and behavior. The &lt;code&gt;.switch&lt;/code&gt; class sets the width and height of the label and positions it relatively:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Styling switch button */
.switch {
  width: 60px;
  height: 35px;
  display: inline-block;
  cursor: pointer;
  position: relative;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.slider&lt;/code&gt; class positions the slider element absolutely within its container, ensuring it fills the entire area with flush positioning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Styling slider button */ 
.switch .slider {
  position: absolute;
  inset: 0;
  background: rgb(145, 145, 145);
  border-radius: 25px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To hide the checkbox, set its display property to &lt;code&gt;none&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Hiding checkbox input */ 
.switch input {
  display: none;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;::before&lt;/code&gt; pseudo-class, add a blank content before the slider to center the toggle button and change its appearance to circular:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Styling slider appearance */
.switch .slider::before {
  content: "";
  position: absolute;
  height: 27px;
  width: 27px;
  left: 5px;
  top: 4px;
  background: white;
  transition: 0.5s all;
  border-radius: 50%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwt5kp0sdippg0omqdf8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwt5kp0sdippg0omqdf8i.png" alt="Switch button without toggling effect" width="197" height="120"&gt;&lt;/a&gt;&lt;br&gt;
By leveraging the &lt;code&gt;:checked&lt;/code&gt; pseudo-class, we modify the background color of the slider to green when the switch is toggled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Styling checked state */
.switch input:checked + .slider {
  background: rgb(12, 235, 12);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, to enable the slider button to move when toggled, use the &lt;code&gt;transform&lt;/code&gt; property to translate it horizontally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; /* Styling slider movement */
.switch input:checked + .slider::before {
  transform: translateX(23px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These CSS rules make sure the switch button works smoothly. It changes its look and moves as expected when you toggle it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmd04hdynvdtmnlkdbhqy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmd04hdynvdtmnlkdbhqy.gif" alt="fully functional iOS-style switch button" width="306" height="195"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Adding JavaScript for Interactivity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a file named &lt;code&gt;main.js&lt;/code&gt; and link it to your HTML file. Use the following JavaScript code to change the icon when toggling:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Main.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const svgIcon = document.querySelector("#svg-icon");

const handleChange = () =&amp;gt; {
  // Toggle icon based on switch state
  if (document.getElementById("switch-1").checked) {
    svgIcon.src = "./active.svg";
  } else {
    svgIcon.src = "./nonActive.svg";
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Creating an iOS-style switch button for your web applications is achievable with basic knowledge of HTML, CSS, and JavaScript. By following the simple steps outlined in this guide. Feel free to customize the styling and functionality to suit your specific needs and preferences.&lt;/p&gt;

&lt;p&gt;For the full code and resources used in this tutorial, you can find them in my GitHub repository: &lt;a href="https://github.com/Bishal-Pahari/iOS-Button" rel="noopener noreferrer"&gt;https://github.com/Bishal-Pahari/iOS-Button&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simple Introduction to Higher Order Components in React</title>
      <dc:creator>Bishal Pahari</dc:creator>
      <pubDate>Sat, 16 Mar 2024 04:19:36 +0000</pubDate>
      <link>https://dev.to/bishalpahari/simple-introduction-to-higher-order-components-in-react-428</link>
      <guid>https://dev.to/bishalpahari/simple-introduction-to-higher-order-components-in-react-428</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Have you ever heard of Higher Order Components (HOCs)? Don’t let the fancy name intimidate you! Think of them as powerful tools in React that can make your life easier when building complex applications. In this article, we’ll take a simple dive into what Higher Order Components are, why they’re useful, and how they can level up your React development skills without getting tangled in complex jargon.&lt;/p&gt;

&lt;p&gt;So, grab your favorite beverage, settle into your comfy chair, and let’s explore the world of Higher Order Components together!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Higher Order Components?&lt;/strong&gt;&lt;br&gt;
Higher Order Components offer several benefits in React development. Firstly, it helps in reusing logic across multiple components. They simplify handling common functionalities like authentication, logging, or data fetching. With HOCs, you can separate concerns and keep your components focused on their specific tasks. HOCs enable composing multiple behaviors or features into a single component effortlessly. Additionally, they make the code cleaner and easier to understand by moving complex logic out of components. This organization helps keep components focused on their main tasks, resulting in more organized and maintainable code overall&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use Higher Order Components?&lt;/strong&gt;&lt;br&gt;
Imagine we have a dashboard, a profile page, and a settings page in our React application. Each of these pages requires the user to be logged in before accessing the content. Instead of writing authentication logic separately for each component, we can create a single Higher Order Component called &lt;code&gt;withAuth&lt;/code&gt; that wraps around these components.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;withAuth&lt;/code&gt; HOC can check if the user is authenticated. If the user is authenticated, it renders the component; otherwise, it redirects the user to the login page.&lt;/p&gt;

&lt;p&gt;This approach helps in keeping our code clean, modular, and easy to maintain. If the authentication logic needs to be updated or modified, we only need to do it in one place, inside the &lt;code&gt;withAuth&lt;/code&gt; HOC, rather than updating it in multiple components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing Higher Order Components in your React App&lt;/strong&gt;&lt;br&gt;
I will try to explain to you the concept of Higher Order Components (HOCs) using a simple analogy that involves cookies:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1b62hqd2kf8j8eqq7qo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1b62hqd2kf8j8eqq7qo.png" alt=" " width="800" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you have two cookies, and you want to add chocolate chips on top of each one. Now think if you only have two cookies, it’s easy to manually place the chocolate chips on each cookie. But what if you have a hundred cookies? Doing it manually for each cookie would take forever!&lt;/p&gt;

&lt;p&gt;This is where Higher Order Components (HOCs) come in handy. Think of the cookies as your components and the chocolate chips as some extra functionality or props you want to add to them. With a HOC, you can create a special function that automatically adds the chocolate chips to each cookie component without having to do it manually for each one. So, whether you have two cookies or a hundred, the HOC takes care of the job for you, making your life as a baker (or developer) much easier!&lt;/p&gt;

&lt;p&gt;First, let’s create a file called &lt;code&gt;App.js&lt;/code&gt;, which will be our entry point of our React application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;App.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import Cookie1 from "./components/Cookie1";
import Cookie2 from "./components/Cookie2";

const App = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Cookies with Chocolate Chips:&amp;lt;/h1&amp;gt;
      &amp;lt;Cookie1 /&amp;gt;
      &amp;lt;Cookie2 /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s create a file called &lt;code&gt;HOC.js&lt;/code&gt;, which will be our Higher Order Component (HOC) responsible for adding chocolate chips to our cookies.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;HOC.js&lt;/em&gt;&lt;br&gt;
We define our Higher Order Component called &lt;code&gt;WithComponentChips&lt;/code&gt;. This function takes a &lt;code&gt;WrappedComponent&lt;/code&gt; as input and returns an enhanced version of it. In this case, it adds functionality to track and display the number of chocolate chips added to the cookies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

const WithComponentChips = (WrappedComponent) =&amp;gt; {
  const EnhancedComponent = () =&amp;gt; {
    const [addChocolateChips, setAddChocolateChips] = useState(0);
    const handleChange = () =&amp;gt; {
      setAddChocolateChips(addChocolateChips + 1);
    };
    return (
      &amp;lt;WrappedComponent
        addChocolateChips={addChocolateChips}
        handleChange={handleChange}
      /&amp;gt;
    );
  };
  return EnhancedComponent;
};

export default WithComponentChips;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s create another file called &lt;code&gt;Cookie1.js&lt;/code&gt; &amp;amp; &lt;code&gt;Cookie2.js&lt;/code&gt;, which will represent our cookie component.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cookie1.jsx&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import WithComponentChips from "../HOC";

const Cookie1 = ({ addChocolateChips, handleChange }) =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt; {addChocolateChips} 🍫 Chocolate Chips 🍫&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={handleChange}&amp;gt;Add Chocolate Chip&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default WithComponentChips(Cookie1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Cookie2.jsx&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import WithComponentChips from "../HOC";

const Cookie2 = ({ addChocolateChips, handleChange }) =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt; {addChocolateChips} 🍫 Chocolate Chips 🍫&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={handleChange}&amp;gt;Add Chocolate Chip&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default WithComponentChips(Cookie2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These files represent our individual cookie components. They receive props &lt;code&gt;addChocolateChips&lt;/code&gt; and &lt;code&gt;handleChange&lt;/code&gt; from the Higher Order Component. Each component displays the number of chocolate chips added and includes a button to add more chips when clicked.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7e3j6ne1s72fmndzkyqe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7e3j6ne1s72fmndzkyqe.png" alt=" " width="550" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The magic happens when we export the &lt;code&gt;Cookie1.jsx&lt;/code&gt; and &lt;code&gt;Cookie2.jsx&lt;/code&gt; components after enhancing them with the &lt;code&gt;WithComponentChips&lt;/code&gt; HOC. By doing so, both cookies automatically gain the ability to track and add chocolate chips without us having to manually add this functionality to each one individually.&lt;/p&gt;

&lt;p&gt;This example demonstrates how Higher Order Components (HOCs) can make it easier to add extra features to lots of components in our React app. It’s like adding chocolate chips to cookies — instead of doing it one by one, we use a special method that does it automatically for all our cookies. So, whether we have just a couple of cookies or a whole bunch, the HOC does the work for us, making our code neater and simpler to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this guide to Higher Order Components (HOCs) in React, we’ve learned how they make building apps easier. HOCs are like special helpers that let us add extra features to lots of components without repeating ourselves. We saw how they help keep our code organized, by separating different tasks into smaller pieces. Using a simple example with cookies and chocolate chips, we understood how HOCs work: just like adding chocolate chips to cookies, we can use HOCs to automatically add functionality to our components. Whether we have a few components or many, HOCs do the hard work for us, making our code cleaner and simpler to manage.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
