<?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: Arun Kumar</title>
    <description>The latest articles on DEV Community by Arun Kumar (@arunkumar413).</description>
    <link>https://dev.to/arunkumar413</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F186353%2Faa1acc41-3434-4127-9cb1-692eb1ddbc16.png</url>
      <title>DEV Community: Arun Kumar</title>
      <link>https://dev.to/arunkumar413</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arunkumar413"/>
    <language>en</language>
    <item>
      <title>How does the values in react template part are in sync with local storage?</title>
      <dc:creator>Arun Kumar</dc:creator>
      <pubDate>Wed, 22 Sep 2021 08:26:41 +0000</pubDate>
      <link>https://dev.to/arunkumar413/how-does-the-values-in-react-template-part-are-in-sync-with-local-storage-4d39</link>
      <guid>https://dev.to/arunkumar413/how-does-the-values-in-react-template-part-are-in-sync-with-local-storage-4d39</guid>
      <description>&lt;p&gt;Hi Team,&lt;/p&gt;

&lt;p&gt;I'm trying to use &lt;code&gt;localStorage&lt;/code&gt; for state management. In the below code if I remove the &lt;code&gt;setState&lt;/code&gt; call in the &lt;code&gt;handleChange&lt;/code&gt; function, the template isn't in sync with the localstorage. However if I use the &lt;code&gt;setState&lt;/code&gt; then the values in localStorage in reflecting the template. Any idea on how the presence of setState is allowing the synchronization.&lt;/p&gt;

&lt;p&gt;Here is the code sandbox link: &lt;a href="https://codesandbox.io/s/loving-taussig-p7phs?file=/src/App.js"&gt;https://codesandbox.io/s/loving-taussig-p7phs?file=/src/App.js&lt;/a&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, { useState, useEffect } from "react";

export default function App(props) {
  const [state, setState] = useState({ name: "", city: "" });

  const handleChange = (evt) =&amp;gt; {
    setState(function (state) {
      return { ...state, [evt.target.name]: evt.target.value };
    });
    localStorage.setItem([evt.target.name], evt.target.value);
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt; Home&amp;lt;/h2&amp;gt;
      &amp;lt;input
        placeholder="Name"
        name="name"
        value={localStorage.getItem("name")}
        onChange={handleChange}
      /&amp;gt;
      &amp;lt;input
        name="city"
        placeholder="City"
        value={localStorage.getItem("city")}
        onChange={handleChange}
      /&amp;gt;

      &amp;lt;h3&amp;gt; {localStorage.getItem("name")} &amp;lt;/h3&amp;gt;
      &amp;lt;h3&amp;gt; {localStorage.getItem("city")} &amp;lt;/h3&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
    </item>
    <item>
      <title>Using serviceworker and workbox in react app</title>
      <dc:creator>Arun Kumar</dc:creator>
      <pubDate>Fri, 27 Dec 2019 12:33:28 +0000</pubDate>
      <link>https://dev.to/arunkumar413/using-serviceworker-and-workbox-in-react-app-536n</link>
      <guid>https://dev.to/arunkumar413/using-serviceworker-and-workbox-in-react-app-536n</guid>
      <description>&lt;p&gt;I'm trying to make a react pwa app using the service workers and Google workbox. The custom-service-worker file is in the /public folder of the react app and the default ServiceWorker.js file create by react app is in the /src.&lt;br&gt;
I'm getting below error. Any idea on why this error is occuring? Should I refer to the custom-service-worker.js file in the index.html file?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://127.0.0.1:8080/precache-manifest.293755a47c2781150c8b4c921fc7a770.js' failed to load.
    at http://127.0.0.1:8080/service-worker.js:16:1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is the content of the service-worker file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js');
if (workbox) {
  console.log(`Yay! Workbox is loaded 🎉`);
} else {
  console.log(`Boo! Workbox didn't load 😬`);
}
  workbox.routing.registerRoute(
    // Cache CSS files.
    /\.css$/,
    // Use cache but update in the background.
    new workbox.strategies.StaleWhileRevalidate({
      // Use a custom cache name.
      cacheName: 'css-cache',
    })
  );
  workbox.routing.registerRoute(
    new RegExp('https://jsonplaceholder.typicode.com/posts'),
    new workbox.strategies.StaleWhileRevalidate({
      cacheName: 'app-cache',
    })
  );

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>help</category>
      <category>react</category>
    </item>
  </channel>
</rss>
