<?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 Naveen DA on Medium]]></title>
        <description><![CDATA[Stories by Naveen DA on Medium]]></description>
        <link>https://medium.com/@naveenda?source=rss-d5a923ddb25b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M5RzDcyh7z_OkignP1UNUg.jpeg</url>
            <title>Stories by Naveen DA on Medium</title>
            <link>https://medium.com/@naveenda?source=rss-d5a923ddb25b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 11:44:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naveenda/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[We parsed 10,000 resumes in Next.js. Here’s what actually broke.]]></title>
            <link>https://javascript.plainenglish.io/we-parsed-10-000-resumes-in-next-js-heres-what-actually-broke-cdbc821b4fe7?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdbc821b4fe7</guid>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Thu, 04 Jun 2026 12:06:09 GMT</pubDate>
            <atom:updated>2026-06-04T12:06:09.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6oaJlXCBzF2MD222KvS9oA.png" /></figure><p>Students in India apply to campus placements with resumes that span a surprisingly wide range: clean single-column PDFs, two-column Canva exports, .docx files with embedded images, and occasionally .doc files last touched in 2019. When we built <a href="https://resumegrade.ai/">ResumeGrade</a>, a placement readiness tool for Indian universities, we had to handle all of it reliably. This post covers the three parts that were harder than we expected: parsing, scoring, and multi-tenancy.</p><p>Here’s the full pipeline before we get into the details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhW48urNlrJlS_GTqrVt4w.png" /></figure><h3>Why pdf-parse v1 is locked and you shouldn’t touch it</h3><p>The parsing pipeline lives in a single Next.js route handler at app/api/analyze/route.ts, and the first line of that file says:</p><pre>export const runtime = &quot;nodejs&quot;;</pre><p>That declaration is load-bearing. pdf-parse, mammoth, and word-extractor all need Node APIs that aren&#39;t available in Vercel&#39;s Edge runtime. If you deploy this to Edge, you get a silent failure at cold start rather than a helpful error. We learned this after a confusing 30 minutes of undefined is not a function in production.</p><p>For PDFs, we use pdf-parse v1. Not v2. The v2 API switched to a class-based interface and changed how it handles password-protected and malformed PDFs. Since we can&#39;t control what students upload, we stay on the functional API:</p><pre>const pdfParse = (await import(&quot;pdf-parse&quot;)).default;<br>const result = await pdfParse(buffer);<br>// result.text, result.numpages</pre><p>The dynamic import matters. pdf-parse reads test fixtures from disk at require time when it detects a test environment. If you import it at the top of the file in certain environments, it throws on the fixture path before you get to call it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mKphYXsC0m9LOYEVvZ5l-A.png" /></figure><p>For .docx, we use mammoth. For old binary .doc files, we use word-extractor. The page count for Word documents is estimated from word count divided by 400 (rough words-per-page for a resume), since neither library exposes actual page metadata.</p><p>What we don’t handle well: multi-column PDF layouts. pdf-parse extracts text in reading order based on character positions, but two-column PDFs often interleave content from the left and right columns. A resume with skills on the left and experience on the right comes out as &quot;Python JavaScript React Java Spring AWS Led a team of...&quot; with the skills and experience merged into one stream. We detect two-column layouts with a separate vision call (more on that below) and flag them in the score, but we don&#39;t fix the extraction.</p><h3>Why a deterministic rubric alone gives you a score nobody trusts</h3><p>The first version of our scorer was purely rule-based. It checked ~40 things: presence of quantified bullets, buzzword density, passive voice (“was responsible for”), date format consistency, contact info completeness, section headers, action verb distribution. Each check contributed to a weighted score. We could explain exactly why a resume scored 68 instead of 74.</p><p>The problem: a resume that passed every check could still read like it was written by someone who memorized a checklist. “Led a cross-functional team to achieve a 15% improvement in delivery timelines” passes our action verb check, our quantification check, our passive voice check. It’s technically correct. It’s also the exact sentence pattern that appears in thousands of bad resumes.</p><p>We added a second layer: GPT-4o with structured JSON output.</p><pre>const response = await openai.chat.completions.create({<br>  model: &quot;gpt-4o&quot;,<br>  response_format: { type: &quot;json_object&quot; },<br>  messages: [{ role: &quot;user&quot;, content: prompt }],<br>  temperature: 0,<br>  max_tokens: 2000,<br>});</pre><p>The LLM does four things the rubric can’t:</p><p><strong>Bullet-level feedback:</strong></p><p>For each work experience bullet, it rates quantification (0–10), action verb quality (0–10), and whether it describes an accomplishment vs. a duty. It flags generic filler (“Worked on various projects”) and returns rewrite suggestions.</p><p><strong>Rubric corrections:</strong></p><p>Some rubric checks produce false positives. “Managed a team” passes our action verb check but is weak. “Ensured quality” sounds like an action verb but isn’t. The LLM layer can override specific rubric outcomes with corrections, so the final score is a merge of deterministic checks and LLM overrides.</p><p><strong>Holistic score:</strong></p><p>The LLM generates an independent 0–100 placement-readiness score with its own reasoning. We show this alongside the rubric score so students can see whether the two agree. When they diverge significantly, it usually means the resume passes technical checks but has substantive content problems.</p><p><strong>Visual signals via vision:</strong></p><p>A separate call sends a PNG render of the resume to GPT-4o vision to detect layout type, photo presence, decorative icons, and visual clutter. This runs concurrently with the text analysis.</p><p>The tricky part is merging all of this reliably. GPT-4o with response_format: { type: &quot;json_object&quot; } is good but not perfect. The model occasionally returns valid JSON that doesn&#39;t match the schema we specified in the prompt. We handle this with a parseLlmJson utility that validates the structure and falls back to defaults on unexpected shapes rather than throwing.</p><p>One constraint we enforce at the prompt level for the rewrite feature:</p><blockquote><em>“Do not add achievements, numbers, or claims not present in the original. Only rephrase and restructure.”</em></blockquote><p>Without this, the model freely invents metrics. Students have caught this when GPT suggested they “reduced deployment time by 40%” for a project where they never measured deployment time. The guardrail makes rewrites less impressive but actually trustworthy.</p><h3>Multi-tenancy in Supabase, and the RLS recursion trap</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hfmnTh2XU9mrS8oPldSqOg.png" /></figure><p>Each university is an organisation. Students, placement officers, and advisors belong to an org. A placement officer at one university should not see students from another. This is the core isolation requirement.</p><p>The data model is:</p><pre>organisations<br>  └── org_members       (who belongs to this org + their role)<br>  └── students          (student roster, imported by placement officers)<br>  └── cohorts           (graduation year batches)<br>      └── scans         (each resume upload + score result)</pre><p>We use Supabase RLS policies on every table. The organisations table policy checks is_org_member(id):</p><pre>CREATE POLICY &quot;org_members can read their org&quot;<br>  ON organisations FOR SELECT<br>  USING (public.is_org_member(id));</pre><p>And students checks org_id:</p><pre>CREATE POLICY &quot;org_members can read students&quot;<br>  ON students FOR SELECT<br>  USING (public.is_org_member(org_id));</pre><p>This worked fine until we hit an infinite recursion in production.</p><p>is_org_member() checks the org_members table. The org_members table has its own RLS SELECT policy that calls is_org_member(). So: SELECT on org_members triggers the policy, which calls is_org_member(), which runs SELECT on org_members, which triggers the policy again. Infinite loop. Postgres returns ERROR: infinite recursion detected in policy for relation &quot;org_members&quot;.</p><p>The fix is to make is_org_member() a SECURITY DEFINER function that bypasses RLS on its own read:</p><pre>CREATE OR REPLACE FUNCTION public.is_org_member(p_org_id UUID)<br>RETURNS BOOLEAN<br>LANGUAGE plpgsql<br>STABLE<br>SECURITY DEFINER<br>SET search_path = public<br>AS $$<br>DECLARE<br>  v_result BOOLEAN;<br>BEGIN<br>  SET LOCAL row_security = off;<br>  SELECT EXISTS (<br>    SELECT 1 FROM public.org_members<br>    WHERE org_id = p_org_id<br>      AND user_id = auth.uid()<br>  ) INTO v_result;<br>  RETURN v_result;<br>END;<br>$$;</pre><p>SET LOCAL row_security = off disables RLS for that session scope. Because the function is SECURITY DEFINER, it runs with the privileges of its owner (postgres superuser), not the calling user. The SET search_path = public prevents search path injection. This is the standard Supabase pattern for breaking RLS cycles, and it&#39;s in their docs, but it&#39;s easy to miss when you&#39;re in the middle of a late-night incident.</p><p>Why Supabase over a custom auth setup? Mostly because we needed Postgres, not a black-box database. The auth model, RLS, edge functions, and row-level policies all live alongside the actual data schema. When something breaks, we can inspect and fix it in SQL. We didn’t want to own a user management service on top of everything else.</p><h3>What we’d do differently</h3><p>The parser handles about 92% of uploaded resumes cleanly. The 8% failure rate is mostly two-column PDFs and old binary .doc files with complex formatting. We&#39;ve considered switching to a PDF rendering approach (convert to image, use vision to extract structure) but the latency tradeoff isn&#39;t worth it for most uploads.</p><p>The LLM cost per analysis is around $0.006 at current GPT-4o pricing. That’s fine for individual student uploads but adds up fast for batch processing. We run batch analyses with gpt-4o-mini for the bullet feedback pass and reserve gpt-4o for the holistic score and visual analysis.</p><p>The RLS recursion issue showed up six days before our pilot launch with the first university. It was in production, not dev, because the query patterns that trigger it require a logged-in user with a real org membership. Unit tests don’t catch this.</p><p>If you’re building something in the same space or have questions about the parser or scoring architecture, you can try the tool at <a href="https://resumegrade.ai/">resumegrade.ai</a> or reach out directly. The resume builder and scoring engine are the same ones used in the university portal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdbc821b4fe7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/we-parsed-10-000-resumes-in-next-js-heres-what-actually-broke-cdbc821b4fe7">We parsed 10,000 resumes in Next.js. Here’s what actually broke.</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[How to Creating a custom 404 Page with React Routers V6?]]></title>
            <link>https://naveenda.medium.com/how-to-creating-a-custom-404-page-with-react-routers-v6-52efe2cd3807?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/52efe2cd3807</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[router]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Sat, 31 Dec 2022 01:50:19 GMT</pubDate>
            <atom:updated>2022-12-31T01:50:19.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1Lcve0xiNGjii1TnDhPjw.png" /></figure><p>React Router is a popular JavaScript library for building single-page applications with React. It provides a set of components and functions that enable you to declaratively define your application’s routing and navigation.</p><p>In this blog post, we will look at how to create a custom 404 page with React Router v6. A 404 page is a page that is displayed when a user tries to access a URL that does not exist on your website. By default, React Router will display a simple “404 — Page Not Found” message when a user tries to access a URL that does not match any of the routes in your application. However, you can customise this message by creating a custom 404 page using the NotFound component provided by the library.</p><pre>const NotFound = () =&gt; {<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;404 - Page Not Found&lt;/h1&gt;<br>      &lt;p&gt;Sorry, the page you are looking for could not be found.&lt;/p&gt;<br>    &lt;/&gt;<br>  );<br>};<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Router&gt;<br>      &lt;Switch&gt;<br>        &lt;Route exact path=&quot;/&quot;&gt;<br>          &lt;Home /&gt;<br>        &lt;/Route&gt;<br>        &lt;Route path=&quot;/about&quot;&gt;<br>          &lt;About /&gt;<br>        &lt;/Route&gt;<br>        &lt;Route path=&quot;/contact&quot;&gt;<br>          &lt;Contact /&gt;<br>        &lt;/Route&gt;<br>        {/* This is where magic happens */}<br>        &lt;Route path=&quot;*&quot; element={&lt;NotFound /&gt;} /&gt;<br>      &lt;/Switch&gt;<br>    &lt;/Router&gt;<br>  );<br>};</pre><p>“The NotFound component should be placed at the bottom of the Switch component in a React Router application so that it will only be rendered if none of the other routes in the Switch component match the current URL. This allows the NotFound component to act as a catch-all or wildcard route that handles URLs that do not match any of the defined routes in the application.&quot;</p><p>Happy coding👩‍💻👨‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52efe2cd3807" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Ways to Style a React Application]]></title>
            <link>https://javascript.plainenglish.io/10-ways-to-style-a-react-application-29db8f1f8fd0?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/29db8f1f8fd0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 10:43:25 GMT</pubDate>
            <atom:updated>2025-06-12T22:17:09.873Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4j07NC-WiPIsX8VzaLPITA.png" /></figure><p>React is a library for rendering UI, it doesn’t care about styling. It is a nice thing about React, but it also leaves us alone in a big ocean with a lot of options.</p><p>Usually, choosing the style system for your React application is not as hard as it seems. Also, you don’t have to use all the 10 ways listed in the article.</p><p>It is good to know the all available options, so you can choose the best based on the situation.</p><ol><li>Inline Style</li><li>Style Sheets</li><li>CSS Module</li><li>CSS Pre-Processor</li><li>Styled Components</li><li>React JSS</li><li>Radium</li><li>JSX Styles</li><li>React Shadow</li><li>Utility CSS Frameworks</li></ol><h4>1. Inline</h4><p>Inline CSS are the same as like regular style tag.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9c9820c48519ca89ddc6a9eba1b44cf/href">https://medium.com/media/a9c9820c48519ca89ddc6a9eba1b44cf/href</a></iframe><h4><strong>2. Style Sheets</strong></h4><p>Stylesheets are very common in the react eco-system and it is cool. The only problem is isolating the styles from another component is pretty hard.</p><p>We create regular stylesheets and import them on your components</p><pre>.container{<br>  width: 100%;<br>  padding: 12px;<br>  background: red;<br>}</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cb36f26edd91c543fb6960b30292bce/href">https://medium.com/media/9cb36f26edd91c543fb6960b30292bce/href</a></iframe><p>By default, the Create-React-App did some steps to make it production-ready by using PostCSS.</p><h4><strong>3. CSS Modules</strong></h4><p><a href="https://github.com/css-modules/css-modules">CSS module</a> solves the style isolating issue by creating a unique class name for every class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OadDCcFhLnSFCHdW" /></figure><p>Create-React-App has inbuild support for the CSS Modules. CSS Module allows us to use the same class name with files without worrying about the CSS name clash.</p><p>For example, we have the same class container on two different files</p><pre>// homepage.module.css<strong><br>.container</strong>{<br>  padding:12px;<br>  background:red;<br>}</pre><p>If we have the same class name in another file.</p><pre>// contactpage.module.css<br><strong>.container</strong>{<br>  padding: 12px;<br>  background:green;<br>}</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f025356dc188ec82d45853a28f041619/href">https://medium.com/media/f025356dc188ec82d45853a28f041619/href</a></iframe><h4><strong>4. CSS Pre-Processor</strong></h4><p>We can use SASS , SCSS , LESS , STYLUS , etc by using webpack loader. But unfortunately, none of them is supported by default in the CRA.</p><p>We can use SCSS or SASS by installing node-sass</p><pre>npm i node-sass</pre><p>For more, please check out the<a href="https://create-react-app.dev/docs/adding-a-sass-stylesheet"> official docs.</a></p><h4>5. Styled Components</h4><p>Instead of writing CSS as JS, the <a href="https://styled-components.com/">styled-component</a> is allowing us to write the actual CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8C0xI2Q_cw6Hmd3U" /></figure><p>Install the styled component via npm</p><pre>npm i styled-components</pre><p>Let us create the same style using styled-componets</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/383b875ea7489e1b495fc5b90a9c5cdd/href">https://medium.com/media/383b875ea7489e1b495fc5b90a9c5cdd/href</a></iframe><p>Styled-Component uses the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates">Tagged Template Literals</a> to create the styles.</p><h4>6. React JSS</h4><p>JSS is allowed to create CSS by using Javascript in a declarative, conflict-free and reusable way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n05vkn3lTieC8i0o" /></figure><p>Install the <a href="https://cssinjs.org/react-jss/?v=v10.7.1">react-jss</a> using npm</p><pre>npm i react-jss</pre><p>Then create the style using createUseStyles</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5996f0165307631f9416855add81110b/href">https://medium.com/media/5996f0165307631f9416855add81110b/href</a></iframe><h4>7. Radium</h4><p>Radium is a set of tools to create<strong> inline styles</strong> using javascript. The Radium did some<a href="https://javascript.plainenglish.io/deep-dive-into-tree-shaking-ba2e648b8dcb"> tree-shaking</a> to eliminate dead code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fzCnPEjUlDFOhIHW" /></figure><p>By default, react doesn’t allow inline style with pseudo selectors like :hover ,:focus, etc.</p><p>Install the <a href="https://formidable.com/open-source/radium/">radium</a> using npm</p><pre>npm i radium</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b17dafa715d0c2608dbc23c1e75c3b8b/href">https://medium.com/media/b17dafa715d0c2608dbc23c1e75c3b8b/href</a></iframe><h4>8. React Shadow</h4><p>React Shadow allows us to create the Shadow DOM in React with all the benefits of style encapsulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nznwPyHvKLvK6746" /></figure><p>Install the using <a href="https://github.com/Wildhoney/ReactShadow">Reach Shadow</a> using npm</p><pre>npm i react-shadow</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d15476e0a29e0e1e2326c616d9ef7e8c/href">https://medium.com/media/d15476e0a29e0e1e2326c616d9ef7e8c/href</a></iframe><h4>9. JSX Style</h4><p><a href="https://github.com/jsxstyle/jsxstyle">jsxstyle</a> is an <strong>inline style system</strong> for React and Preact. It provides a best-in-class developer experience without sacrificing performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eRaMVihOufDLVahl" /></figure><p>Install the <a href="https://github.com/jsxstyle/jsxstyle">jsxstyle</a> using npm</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23c73678763176e324aa24e6c0e114b0/href">https://medium.com/media/23c73678763176e324aa24e6c0e114b0/href</a></iframe><h4>10. Utility Frameworks</h4><p>Utility frameworks are created to avoid creating a style sheet. The most famous utility framework is <a href="https://tailwindcss.com/">tailwindcss</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VWqYWAiNaTq73nZB" /></figure><p>CRA is doesn’t support tailwindcss natively, we need to use some CRA override like CRACO.</p><p>For more info, please check out <a href="https://tailwindcss.com/docs/guides/create-react-app">official docs</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80193e37576e79c8f27d49c0538b0ae0/href">https://medium.com/media/80193e37576e79c8f27d49c0538b0ae0/href</a></iframe><p>Hope you enjoy this article.</p><p>Happy reading <strong>❤️</strong>.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29db8f1f8fd0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/10-ways-to-style-a-react-application-29db8f1f8fd0">10 Ways to Style a React Application</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[Div === Span ]]></title>
            <link>https://naveenda.medium.com/div-span-d4c496e61294?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4c496e61294</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Fri, 30 Jul 2021 07:47:46 GMT</pubDate>
            <atom:updated>2021-08-07T09:59:48.195Z</atom:updated>
            <content:encoded><![CDATA[<h4>In CSS div is equal to span. Yes, you heard that right!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tf70ieavT9eL9yTmUmN7cA.png" /></figure><p>Edit:</p><p><strong>By Default, the display property of </strong><strong>div and </strong><strong>span is inline not block and inline. The rest of the article is telling about the same thing. So skip this article and try to read another interesting article.</strong></p><p>— Sorry to waste your precious time —</p><p>You might know, a div is a block-level element and the span is an inline-block level element. And you might know the difference between display:block and display:inline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOjI8AHidOgMWRl4De9vNA.png" /></figure><h4><strong>Why div is equal to span?</strong></h4><p>When you inspect the div it shows display:block</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dc9MESezkFvsgxuzpJG82w.png" /></figure><p>A div is a block-level element and span is an inline-block level element, then why is it equal.</p><p><strong>div and </strong><strong>span both are inline-block element</strong></p><p>Have ever wonder why the browser shows<strong> </strong>the<strong> user agent stylesheet </strong>in the styles tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5Q2rTf0JAwyDDAJ5Lcn7A.png" /></figure><p>These styles are provided by the browser.</p><p>When you reset the display using display:initial , you will find the display default value for div</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fU7LyDCaVNvpNvDAZPvO5w.png" /></figure><p><strong>Please check out the first comment, which is far far better than this post itself. Also, it contains excellent information.</strong></p><p>Happy reading <strong>❤️</strong>.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4c496e61294" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Dive Into Tree-Shaking]]></title>
            <link>https://javascript.plainenglish.io/deep-dive-into-tree-shaking-ba2e648b8dcb?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba2e648b8dcb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Fri, 23 Jul 2021 14:05:11 GMT</pubDate>
            <atom:updated>2021-07-23T14:05:11.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l7cwtYw0Xa4mcev1JEmXKw.png" /></figure><p>In the JavaScript world, the term tree-shaking refers to the <strong>removal of dead code. </strong>But this terminology is not limited to JavaScript, the word “tree-shaking” comes from Lisp Community in the 1990s.</p><p>Thanks to <a href="https://twitter.com/rauschma/status/678835068165595136"><strong>Axel Rauschmayer</strong></a>, who turns himself into Indiana jones and find the exact origin of this word on Twitter.</p><h3>Axel Rauschmayer on Twitter: &quot;@Rich_Harris Do you know where the term &quot;tree-shaking&quot; comes from? Haven&#39;t seen it before Rollup. / Twitter&quot;</h3><p>@Rich_Harris Do you know where the term &quot;tree-shaking&quot; comes from? Haven&#39;t seen it before Rollup.</p><p>When I first heard about this topic, I was so excited to learn about tree-shaking. So I googled it.</p><p>According to <a href="https://en.wikipedia.org/wiki/Tree_shaking">Wikipedia</a>, the tree-shaking algorithm was used in the dart to remove the dead code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngEul2nNjoEYrC9qK_8oBQ.png" /><figcaption><a href="https://en.wikipedia.org/wiki/Tree_shaking">https://en.wikipedia.org/wiki/Tree_shaking</a></figcaption></figure><p>I rush into the <a href="https://github.com/dart-lang/site-www/search?q=tree-shaking&amp;unscoped_q=tree-shaking">Dart GitHub repo</a> and found this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xegdgcOCYGhlov1Qfgam6A.png" /><figcaption><a href="https://github.com/dart-lang/site-www/search?q=tree-shaking&amp;unscoped_q=tree-shaking">https://github.com/dart-lang/site-www/search?q=tree-shaking&amp;unscoped_q=tree-shaking</a></figcaption></figure><p><strong>Thanks, Google!</strong></p><p>StackOverflow has a question about the Tree-Shaking with an excellent answer.</p><p><a href="https://stackoverflow.com/questions/45884414/what-is-tree-shaking-and-why-would-i-need-it">What is Tree Shaking and Why Would I Need It?</a></p><p>At this point, I realize only a few articles were written about the Tree-Shaking and its methodology.</p><p>After reading a lot of available articles about Tree-Shaking, I decided to write an article about 3 different sets of methodologies.</p><ol><li>Import Tree-Shaking</li><li>Environmental variables Tree-Shaking</li><li>CSS Tree-Shaking</li></ol><h3>Why is it called Tree-Shaking?</h3><p>Let’s consider the following code as an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*yRhVrGdSC53TIgd2uMmbKw.png" /></figure><p>Rollup REPL: <a href="https://bit.ly/2UaKxTV">https://bit.ly/2UaKxTV</a></p><p>The file main.js uses 3 methods (square cube log) from two files and those files have some extra methods, which is not used and are not going to run. Therefore those codes are <strong>dead codes </strong>we need to remove them.</p><p>For the sake of understanding, we need to convert these dependencies as a tree or technically <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">Abstract syntax tree</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WLs-D7X4pRhlAaGgPQyoJQ.png" /></figure><p>Let’s assume these dependencies graphs as a regular tree with the branch, trunk, etc. If you feel hard to imagine these graphs as a tree, no worries I will do it for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSGarX2X9GrQAxLm1Xl8mg.png" /></figure><p>Much Better!</p><p>Now mark all the dead codes in red colour and use blue colour codes for a better understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3Hv2BfLIY1MvPZJiczUvA.png" /></figure><p>If we shake a tree so hard all the dead branches will fall, the same thing we need to do in our code base.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiI19kqvrINDVunzcuNktA.png" /><figcaption>Tree-Shaking</figcaption></figure><p>Okay, now let’s shake some trees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*I0oJCROpUlmji3b2" /><figcaption><a href="https://tenor.com/view/tree-shaking-shaking-cutting-trees-leaves-gif-15973840">https://tenor.com/view/tree-shaking-shaking-cutting-trees-leaves-gif-15973840</a></figcaption></figure><h3><strong>Import Tree-shaking</strong></h3><p>The concept of tree-shaking exits from the 1990s, but we used this in JavaScript very recently, thanks to ES Static Imports.</p><p>ES Static Imports or Harmony imports are allowed to import specific functions or variables from the different files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sN2IOX6nRwLLIYCY.png" /><figcaption><a href="https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/">https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/</a></figcaption></figure><p>If you want to know more about the es-modules, please check this awesome article on <a href="https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/">Mozilla Hacks</a> by <a href="https://medium.com/u/d3391efe481a">Lin Clark</a>.</p><p>Let’s use the same code, that uses to represent the tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*oxMnT9AlrUESzAwxDildJg.png" /></figure><p>The file main.js is our entry module, in this page we are using only 3 methods out of 8 methods. And all methods are Pure Function, meaning it doesn’t have any extra dependencies and side effects.</p><p>If we removed all the unused methods, our final output will be like these.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*UrcUOUycoKTccIb1xBdadw.png" /><figcaption>With Tree-Shaking</figcaption></figure><p>If the tree-shaking did not occur the final output will be like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*95NpMrPNhqjjJMzKraLfMQ.png" /></figure><h4><strong>How to remove dead code</strong></h4><p>Now the million-dollar question: “How do you remove dead code?”</p><p>Most of the modern build tools, do the tree-shaking to reduce the size of the final bundle. By analysing them, we can understand how they work.</p><p>In general, the tree-shaking will remove the nodes (methods/variable) which is not connected to the root node.</p><p>Let me explain, a little bit further.</p><p>Now, let’s back to the syntax tree (convert code into syntax tree in your mind). If a method or variable is not used in the abstract syntax tree, those functions will not be connected to the root node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/0*qEMSoUA0LZmSXBU3.png" /><figcaption><a href="https://www.gatevidyalay.com/tree-data-structure-tree-terminology/">https://www.gatevidyalay.com/tree-data-structure-tree-terminology/</a></figcaption></figure><p>All we need is to remove the node which is not connected to the root node. Most of the bundlers using an algorithm to find and remove the dead code, which is similar to the <a href="https://en.wikipedia.org/wiki/Tracing_garbage_collection">Mark and Sweep</a> algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/0*9DDxZfEbj2KFu4YS.gif" /><figcaption><a href="https://en.wikipedia.org/wiki/Tracing_garbage_collection">https://en.wikipedia.org/wiki/Tracing_garbage_collection</a></figcaption></figure><p>Mark and Sweep algorithm is generally used in the garbage collector to identify the live and dead objects and remove the dead objects from the memory.</p><p>Tree-shaking is enabled by default in the <a href="https://rollupjs.org/guide/en/">rollup bundler</a>, So we can test our code on the <a href="https://rollupjs.org/repl">rollup REPL</a></p><p>The following output is produced by a rollup for the es-build.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/474cd233ada485d5e6e46c49fc6a93d3/href">https://medium.com/media/474cd233ada485d5e6e46c49fc6a93d3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5WYpZbopdrWBiWBK2tGmg.png" /></figure><h4>What if the function uses another function?</h4><p>Let’s make a change in our method square by adding dependencies. A validation method is added in the square method which used isNumber method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*HB9dtig66yxqnAKVesZtsg.png" /></figure><p>So our final output should include isNumber method too.</p><p>Rollup output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df94c3fcf0cece69e3c9ebcd0d0365dc/href">https://medium.com/media/df94c3fcf0cece69e3c9ebcd0d0365dc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O7yDlJEa1jstNpUKAmbZVg.png" /></figure><p>Bundlers can identify the dependent methods and included them in the final build.</p><p><strong>Note:</strong> The Import Tree-Shaking can be done in commonJS format too, but es import format gives better results.</p><p>For more info: Please refer to this repo: <a href="https://github.com/rollup/plugins/tree/master/packages/commonjs">https://github.com/rollup/plugins/tree/master/packages/commonjs</a></p><h4>Tree-shaking with class</h4><p>Tree-shaking with a class is a different story!</p><p>Let’s refactor code by using a class with the static method in it (non-static method will also work).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*rsreqhMa6KBRIfkKpJ2k9g.png" /></figure><p>In the abstract tree, the class will be connected to the root node its methods.</p><p>So even we haven’t used all the methods, they will be included in the final build.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dd4d68ee800e9d9dede07398c4dbb03/href">https://medium.com/media/7dd4d68ee800e9d9dede07398c4dbb03/href</a></iframe><p>The same things will apply to objects also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtTsnHDp35bjT9j7CK4inw.png" /></figure><p>When writing a modular code, create a mental map of abstraction for that particular code, so that you know the final output.</p><h3><strong>Environmental variables</strong></h3><p>Environmental variables will not change on the runtime, so most bundlers will do the tree-shaking based on the values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/730b0c640aacf45b236220b0949cdc4f/href">https://medium.com/media/730b0c640aacf45b236220b0949cdc4f/href</a></iframe><p>During the build process.</p><p>If the NODE_ENV is true, there is no need for the else part so bundlers will remove it. And there is no need for the if-check because it always will be true.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05a6a115c6858352d309c604b163c9ec/href">https://medium.com/media/05a6a115c6858352d309c604b163c9ec/href</a></iframe><p>If the NODE_ENV is false the bundle do the same thing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db5dffa60e37efca0faf187e0791dd1d/href">https://medium.com/media/db5dffa60e37efca0faf187e0791dd1d/href</a></iframe><p>If the configuration will change on the runtime, consider converting them into environmental variables and use if-checks based on the value.</p><h3>CSS Tree-shaking</h3><p>We can’t apply the Mark-Sweep algorithm for the CSS directly. Yeah, CSS is pretty hard to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/0*mU13cuheQVb2-4Yx" /><figcaption><a href="https://www.reddit.com/r/ProgrammerHumor/comments/8tnztu/backend_developer_doing_css/">https://www.reddit.com/r/ProgrammerHumor/comments/8tnztu/backend_developer_doing_css/</a></figcaption></figure><p>Doing CSS is hard for both frontend and backend dev because there are tons of ways for doing the same thing.</p><p>Luckily! some modern CSS frameworks will help us solve this problem and also they do the <strong>Tree-shaking </strong>with the help of JavaScript.</p><h4>Purge</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KomaeHQjyhsO8VQx.jpg" /></figure><p><a href="https://purgecss.com/">Purge</a> is a set of tools, used to detected and remove unused CSS. It can be used along with webpack postCSS grunt gulp gatsby</p><p>A sample configuration file for webpack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4696bfc36453093efcc335aa18dded42/href">https://medium.com/media/4696bfc36453093efcc335aa18dded42/href</a></iframe><p>Some of the modern CSS frameworks will purge ‘under the hood’ to improve their performance.</p><h4>Tree-Shaking with Tailwind</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VT6n_MUrhKN8T_Bm" /></figure><p><a href="https://tailwindcss.com/">Tailwind</a> shipped with tons of performance features, one of them was <strong>Tree-Shaking.</strong></p><p>The purge uses this regex/[^&lt;&gt;&quot;&#39;`\s]*[^&lt;&gt;&quot;&#39;`\s:]/g to get the class name, so when you construct the class names conditionally, please do construct a full string instead of a partial string.</p><p>Don’t do this:</p><pre>&lt;div class=&quot;text-{{  error  ?  &#39;red&#39;  :  &#39;green&#39;  }}-600&quot;&gt;&lt;/div&gt;</pre><p>Do this instead:</p><pre>&lt;div class=&quot;{{  error  ?  &#39;text-red-600&#39;  :  &#39;text-green-600&#39;  }}&quot;&gt;&lt;/div&gt;</pre><p>To enable the purge, you need to specify the path in your configuration file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5eb4bb19893f07471903110ba7c0c0e4/href">https://medium.com/media/5eb4bb19893f07471903110ba7c0c0e4/href</a></iframe><p>For more detailed info, please check out the <a href="https://tailwindcss.com/docs/optimizing-for-production">official docs</a></p><p>I hope you understand the concept of Tree-Shaking a little bit. If you want to know please use the following links.</p><ol><li><a href="https://webpack.js.org/guides/tree-shaking/">Tree-Shaking in webpack</a> (Offical Docs)</li><li><a href="https://developers.google.com/web/fundamentals/performance/optimizing-javascript/tree-shaking">Reduce JavaScript Payloads with Tree Shaking</a> (Chrome Dev article)</li><li><a href="https://www.smashingmagazine.com/2021/05/tree-shaking-reference-guide/">Tree-Shaking: A Reference Guide</a> (Smashing Magazine Article)</li><li><a href="https://twitter.com/iamakulov/status/1353650650438119424">/*#​__PURE__*/</a> (A awesome Twitter thread about PURE)</li></ol><p>If you have any doubts/suggestions on this article, please leave a comment.</p><p>Also, check out my latest articles</p><ol><li><a href="https://javascript.plainenglish.io/where-to-store-the-json-web-token-jwt-4f76abcd4577">Where Should You Store JSON Web Tokens (JWT)?</a></li><li><a href="https://javascript.plainenglish.io/how-memory-management-works-in-javascript-f07ccd544190">An Entry-Level Guide to Memory Management in JavaScript</a></li><li><a href="https://javascript.plainenglish.io/usequery-instead-of-fetch-while-calling-an-api-ef12964457c5">useQuery Instead of Fetch While Calling an API</a></li></ol><p><strong>Happy Tree-Shaking ❤️</strong></p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba2e648b8dcb" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/deep-dive-into-tree-shaking-ba2e648b8dcb">Deep Dive Into Tree-Shaking</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 useEffect Infinite Loop Patterns]]></title>
            <link>https://javascript.plainenglish.io/5-useeffect-infinite-loop-patterns-2dc9d45a253f?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dc9d45a253f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Fri, 23 Jul 2021 07:46:04 GMT</pubDate>
            <atom:updated>2021-07-23T07:46:04.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="5 useEffect infinite Loop Patterns" src="https://cdn-images-1.medium.com/max/1024/1*2IKJgMYMfKSvzvUB84C-fg.png" /></figure><p>In general, infinite loops are considered bad practices. But in <a href="https://stackoverflow.com/questions/224204/why-use-infinite-loops">some edge cases</a>, you don’t have any choice to choose rather than an infinite loop. It is good to know the infinite loop patterns of React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/0*D1OnmtizHqj5_PWg.png" /></figure><p>When the infinite loop is running without any stop, eventually browser will kill the tab that your code is running. So don’t use Infinite Loop without any breaking point.</p><h3>useEffect</h3><p>useEffect hook allows us to perform side effects in a component. When hooks were introduced the react 16, the useEffect hook is gain more traction than any other hooks. Because it provides combined functionalities of componentDidMount, componentDidUpdateand componentWillUnmount life cycle methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*1KlPFvEoyTyfZ4dY" /></figure><p>useEffect hook triggers the callback function, only if the dependencies were changed. And it uses shallow comparison to compare the values of the hook.</p><p>You can consider the useEffect as a power stone, it is a most powerful stone and if you haven’t handled it properly the stone would destroy you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wCqH7qdfHIiNdbla" /></figure><h4>Without dependency</h4><p>useEffect without dependencies generally consider a bad practice, so always try to avoid it.</p><p>Consider the following code, it will call the API forever.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4984511b709df3ee7732052648ff910/href">https://medium.com/media/a4984511b709df3ee7732052648ff910/href</a></iframe><h4>What’s happening?</h4><p>If the useEffect is triggering the callback only when the dependencies are changes, why we ended with an infinite loop here.</p><p>You need to take into account important another <strong>mantra of React</strong> which is “When state or Props is changing, the component will re-render”.</p><p>In this code, we set the state value using setData on-network call success, it will trigger the component re-render. Since the useEffect doesn’t have value to compare, so it will call the callback.</p><p>And Again Fetch will trigger setData and setData will trigger, the component re-render and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqBTU4z7inqygcjxHifvuw.png" /></figure><h4>How to fix this issue?</h4><p>We need to specify the dependencies as the empty array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/406cda404454a2d84becb6e09561c4be/href">https://medium.com/media/406cda404454a2d84becb6e09561c4be/href</a></iframe><p>According to official docs, <a href="https://reactjs.org/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies">it is <strong>not safe</strong> to omit the dependencies</a></p><h3>Function as dependency</h3><p>useEffect uses shallow object comparison to determine, whether the data was changed or not. Due to weird JavaScript conditional systems😈 .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0be7eb2a574f09aacb74c8b68d906593/href">https://medium.com/media/0be7eb2a574f09aacb74c8b68d906593/href</a></iframe><p>Let consider the following code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de3f58e975b83f659fe5b06248c15ee1/href">https://medium.com/media/de3f58e975b83f659fe5b06248c15ee1/href</a></iframe><p>The function getData is passed as dependencies.</p><p>When you run this code, it will throw Maximum update depth exceeded which means the code having an infinite loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/0*DNAYYFk7mPEILg2y" /></figure><h4>What’s happening?</h4><p>Since useEffect uses the shallow comparison for the compare the values. The shallow comparison for the function will always give false.</p><h4>How to fix it?</h4><p>To fix this issue, we need to use another infinity stone called useCallback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jlC0mlJ4Sx0FKCDvFALddA.png" /></figure><p>useCallback return a <a href="https://en.wikipedia.org/wiki/Memoization">memoized</a> version of callback, which only change when the dependencies change.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c079c7b767742985ae48fc328dc8912/href">https://medium.com/media/9c079c7b767742985ae48fc328dc8912/href</a></iframe><h3>Array as dependency</h3><p>As you might know, the shallow comparison for two is always false, so passing dependencies as an array will also lead to Infinite Loop</p><p>Let us consider the following code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44787a1f32d9429c76fe216a86c3e7f3/href">https://medium.com/media/44787a1f32d9429c76fe216a86c3e7f3/href</a></iframe><p>Here, the array dep passed as dependencies for the useEffect.</p><p>When you run this code, the browser console will throw this error.</p><h4>What’s happening?</h4><p>The shallow comparison of two arrays is always false, so useEffect will always trigger the callback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/0*xKjAD3xLopnANcld.png" /></figure><h4>How to fix it?</h4><p>Since the useCallback return is a function, we can&#39;t use that.</p><p>So, guess what?</p><p>We need to use another hook called useRef</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XaRNyHElsXvqXDYqBWtRJg.png" /></figure><p>useRef returns a mutable object with .current having the initial value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f2991c06db1fd3541ccb480407e64fe/href">https://medium.com/media/1f2991c06db1fd3541ccb480407e64fe/href</a></iframe><h3>Objects as dependency</h3><p>You might guess the shallow comparison of two objects is always false, so the useEffect will trigger the callback always.</p><p>Let us consider this code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06aad38fd41f4deae9bfa51dfc043b8d/href">https://medium.com/media/06aad38fd41f4deae9bfa51dfc043b8d/href</a></iframe><p>data is passed as the dependencies for the useEffect</p><p>When you run this code, your browser console will be thrown an infinity loop error.</p><h4>What’s happening here?</h4><p>The shallow comparison of objects would be false always, so it will trigger the useEffect’s callback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*fvpb4DiYIe3tLyHK.png" /></figure><h4>How to fix it?</h4><p>If we memoize the dependencies, we break the infinity loop. So <strong>how to do that?</strong></p><p>Yes, we are going to use another infinity stone called useMemo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_s2ytfg27m6cyxynSG2oQ.png" /></figure><p>useMemo will only recompute the memoized value when the dependencies have changed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92e42d2b6aff9f54d3bae8516f3977ea/href">https://medium.com/media/92e42d2b6aff9f54d3bae8516f3977ea/href</a></iframe><h3>Wrong dependency</h3><p>Wrong dependencies are nothing to do with React not even javascript. When the wrong dependencies are used, we must take the blame.</p><p>Let us consider the code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/162e5d642859e72cc2adae315b82638e/href">https://medium.com/media/162e5d642859e72cc2adae315b82638e/href</a></iframe><p>I hope there is no need to explain this issue pattern and its fixes. If you want the explanation and fixes, please let me know in the comment.</p><blockquote><strong>Note:</strong> There is plenty of ways to avoid infinite loop inside a React component, I mentioned only a few ways.</blockquote><p>Always use <a href="https://www.npmjs.com/package/eslint-plugin-react-hooks#installation">eslint-plugin-react-hooks</a> or create-react-app, it will help you to find those issues before those get into the production server.</p><p>A company lost 72k in a week due to an infinite loop.</p><p><a href="https://blog.tomilkieway.com/72k-1/">We Burnt $72K testing Firebase + Cloud Run and almost went Bankrupt [Part 1]</a></p><p>So always give special care to our power stone (useEffect).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xrigT-rtRhqECf06Chg9sA.gif" /><figcaption><a href="https://www.nerdyviews.com/2019/06/infinity-gauntlet-keychain.html">https://www.nerdyviews.com/2019/06/infinity-gauntlet-keychain.html</a></figcaption></figure><p>Also, please take a look at my recent articles about React.</p><ol><li><a href="https://javascript.plainenglish.io/usequery-instead-of-fetch-while-calling-an-api-ef12964457c5">useQuery Instead of Fetch While Calling an API</a></li><li><a href="https://javascript.plainenglish.io/why-you-should-use-useswr-instead-of-usestate-when-calling-apis-8b6de5dc18fc">Why You Should Use useSWR Instead of useState When Calling APIs</a></li><li><a href="https://javascript.plainenglish.io/a-detailed-guide-to-using-axios-in-your-react-app-7396f79fb4c2">A Detailed Guide to Using Axios in Your React App</a></li></ol><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dc9d45a253f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/5-useeffect-infinite-loop-patterns-2dc9d45a253f">5 useEffect Infinite Loop Patterns</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[Where Should You Store JSON Web Tokens (JWT)?]]></title>
            <link>https://javascript.plainenglish.io/where-to-store-the-json-web-token-jwt-4f76abcd4577?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f76abcd4577</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 07:02:57 GMT</pubDate>
            <atom:updated>2021-07-24T10:56:47.699Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0upFgLD4cIJ2XewRi9a_5g.png" /><figcaption>Where to Store JWT</figcaption></figure><p>I have been designing and developing web applications for more than 7 years.</p><p>Through these years, I have been seen a lot of authentication mechanisms, some of them are RESTful and others are not. The RESTful services mostly used JSON Web Token (JWT) as an authentication token.</p><p>Whenever I implemented JWT-based authentication, I asked myself this question, “<strong>Where do we store the JWT?”</strong></p><p><em>Edit:</em> This article is focusing only on browser implementation.</p><p>Let’s answer the big question.</p><p>We have three options available for storing the data on the client side and each of those has its own advantages and disadvantages. And the options are:</p><ol><li>Cookie</li><li>localStorage</li><li>Session Storage</li></ol><h4><strong>Cookie</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1iAVWbhDS6gbRS8pBoqA3A.png" /></figure><p>If you set the JWT on cookie, the browser will automatically send the token along with the URL for the Same Site Request. But it is vulnerable to the <a href="https://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF</a>.</p><p>We can protect the site against CSRF by setting a cookie with SameSite=strict</p><p><em>Edit 1:</em> I̶n̶ ̶g̶e̶n̶e̶r̶a̶l̶ ̶p̶e̶o̶p̶l̶e̶ ̶m̶i̶g̶h̶t̶ ̶t̶h̶i̶n̶k̶,̶ ̶X̶S̶S̶ ̶c̶a̶n̶ ̶b̶e̶ ̶d̶e̶f̶e̶a̶t̶e̶d̶ ̶i̶f̶ ̶w̶e̶ ̶s̶e̶t̶ ̶t̶h̶e̶ ̶h̶t̶t̶p̶O̶n̶l̶y̶ ̶f̶l̶a̶g̶,̶ ̶b̶u̶t̶ ̶i̶t̶ ̶i̶s̶ ̶p̶o̶s̶s̶i̶b̶l̶e̶ ̶t̶o̶ ̶a̶t̶t̶a̶c̶k̶ ̶b̶y̶ ̶u̶s̶i̶n̶g̶ ̶X̶S̶T̶ ̶”̶s̶u̶b̶s̶e̶t̶”̶ ̶(̶k̶i̶n̶d̶a̶)̶ ̶o̶f̶ ̶X̶S̶S̶.̶</p><p><em>Edit 2:</em> We can easily defect the XSS by setting httpOnly flag.</p><p><strong>Pros:</strong></p><ol><li>The browser will automatically send the token to the server.</li><li>The same token is available to multiple tabs of your application instance.</li></ol><p><strong>Con:</strong></p><ol><li>Vulnerable to XSS.</li><li>You need to attach the token in the header if you use a protocol like <a href="https://datatracker.ietf.org/doc/html/rfc6750">OAuth 2.0</a>.</li></ol><p><strong>localStorage</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*2la8DIrVgaX40uudxIWUQA.png" /></figure><p>The localStorage doesn’t send the data automatically along with the URL. So you need to implement the system for the auth token for every URL. But the best part is that this method is not vulnerable to CSRF.</p><p><strong>Pros</strong></p><ol><li>Not vulnerable to CSRF.</li><li>The same token is available to multiple tabs of your application instance.</li></ol><p><strong>Con</strong></p><ol><li>Vulnerable to XSS.</li><li>You need to implement a mechanism for the sent the token.</li></ol><p><strong>Session Storage</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*FhxeiWnOsFxjg7pfFSQ-Mg.png" /></figure><p>Session Storage is pretty much the same as Local Storage, except the token will accessible only one tab, once the tab is closed the session got destroyed. So it <strong>not</strong> useful for the feature like <strong>remember me. </strong>But this can be used in the multi-login feature like Tab A is in a different login and Tab B is in different login.</p><p><strong>Pros:</strong></p><ol><li>Not Vulnerable to CSRF.</li><li>Easy to implement Multiple logins in one browser.</li></ol><p><strong>Con:</strong></p><ol><li>Vulnerable to XSS.</li><li>Once the tab is closed, the session data got destroyed.</li></ol><p>You might notice that all the 3 methods have the same con — “<strong>Vulnerable to XSS”. </strong>Yes, all these methods are vulnerable to XSS. Please do care about XSS and always follows the <a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html">best practices</a> for XSS protection.</p><h4><strong>Conclusion</strong></h4><p>Both localStorage and SessionStorage are not protected by the XSS by default.</p><p>However, the Cookie provides a bunch of security options like SameSite ,” HttpOnly , etc. So it is good to go with Cookie.</p><p><strong><em>“Store Your JWT on Cookie with Some Secure Flag.”</em></strong></p><h4>Sidenote:</h4><p>If you use Express,<a href="https://medium.com/hackernoon/express-js-important-npm-packages-related-to-security-2393466e18d5"> these packages</a> might help to improve your application security.</p><p>Also, check out my recent articles</p><ol><li><a href="https://javascript.plainenglish.io/deep-dive-into-tree-shaking-ba2e648b8dcb">Deep Dive Into Tree-Shaking</a>(How to reduce your bundle size)</li><li><a href="https://javascript.plainenglish.io/5-useeffect-infinite-loop-patterns-2dc9d45a253f">5 useEffect Infinite Loop Patterns</a></li></ol><p>I found these articles are useful to me, maybe these can be useful to you.</p><ul><li><a href="https://scotch.io/bar-talk/why-jwts-suck-as-session-tokens">Why JWTs Suck as Session Tokens</a></li><li><a href="https://auth0.com/docs/security/data-security/token-storage#don-t-store-tokens-in-local-storage">Token Storage</a></li><li><a href="https://stackoverflow.com/questions/44133536/is-it-safe-to-store-a-jwt-in-localstorage-with-reactjs">Is it safe to store a JWT in localStorage with ReactJS?</a></li></ul><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f76abcd4577" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/where-to-store-the-json-web-token-jwt-4f76abcd4577">Where Should You Store JSON Web Tokens (JWT)?</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[How Memory Management Works in JavaScript]]></title>
            <link>https://javascript.plainenglish.io/how-memory-management-works-in-javascript-f07ccd544190?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f07ccd544190</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Tue, 22 Jun 2021 11:59:19 GMT</pubDate>
            <atom:updated>2021-06-22T14:09:40.459Z</atom:updated>
            <content:encoded><![CDATA[<h3>An Entry-Level Guide to Memory Management in JavaScript</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMNnCvYPPA_autabOLeiUQ.png" /></figure><p>I have been writing JavaScript code for the last 8 years. Through these years, I learnt a lot about JavaScript like code optimisation, code readability, cross-browser functionality, memory management, etc.</p><p>Back in the day, I was a junior developer. I was doing my work without worrying about performance and memory. When my senior developers were discussing things like memory management, I felt like they were speaking some kind of alien language. Things were going smoothly until one customer reported an issue about page freeze.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ReWlmJAqaL1eILyNLiJbqQ.png" /></figure><p>One customer reported an issue that involved the page becoming unresponsive when a button was clicked and then Chrome closed that page. I initially thought that it might be a problem with Chrome extensions. So, I tested in the incognito mode but the issue was reproduced in incognito mode too.</p><p>After fixing that, I spent a lot of time reading and understanding JavaScript and its compiler.</p><p>I wrote this article in a way that mid-level or entry-level JavaScript developers can understand. If you have any doubts, please leave a comment; I will try to answer those.</p><h3>Memory Leaks</h3><p>Memory leaks is described as the memory that is not required but for some reason, it doesn’t return to the memory pool.</p><p>JavaScript is designed in a way that it will automatically delete the allocated memory once the variable was used, that process is called garbage collection.</p><p>JavaScript compiler uses two different garbage collectors, one is <strong>Major GC</strong> and another one is <strong>Minor GC</strong>.</p><p>For info: <a href="https://v8.dev/blog/trash-talk">https://v8.dev/blog/trash-talk</a></p><p><strong>Major GC</strong>: Major GC collects the garbage from the entire heap.</p><p><strong>Minor GC</strong>: The Minor GC collects garbage in the young generation.</p><p>These are one-line definitions for the Minor and Major GC.</p><p>Let me breakdowns these into simple English.</p><h4>Major GC:</h4><p>Major GC is the main Garbage collector that identifies the live and dead objects and deletes them dead objects. But the Major GC was run on the main thread, so if the GC is called very often the page becomes irresponsive.</p><p><strong>Why Garbage Collection Freeze the page?</strong></p><p>Garage collector runs on the main thread, so it will block all the user inputs and thus the page becomes irresponsive.</p><p>Okay but,</p><p><strong>Why main thread blocks all user input?</strong></p><p>The short answer is Event Loop. And for the long answer, you need to watch this video. An excellent explanation of event loop and JavaScript compiler.</p><p>More info:<a href="https://www.youtube.com/watch?v=8aGhZQkoFbQ">https://www.youtube.com/watch?v=8aGhZQkoFbQ</a></p><h3>General Guide to improve the memory management of your application.</h3><p><strong>1. Global Variables</strong></p><p>The garbage collector never collects the memory of a global variable, so before start declaring a global variable think twice.</p><p>But sometimes, we accidentally introduce a global variable.</p><p>Let see this code</p><pre>function foo(arg) {<br>  bar = &quot;this is a hidden global variable&quot;;<br>}</pre><p>You might notice, the bar not defined but assigns a value so this will become a global variable.</p><p>Here, we leaked a string memory and you might think this won’t create a big problem, But it will override some other global methods and that leads to another breakage.</p><p><strong>2. Reference forever<br></strong>Always do care about memory, when it comes to object and data-binding.</p><pre>function run(){<br>  var domObjects = $(&quot;.myClass&quot;);<br>  domObjects.click(function(){<br>  domObjects.addClass(&quot;.myOtherClass&quot;);<br>  });<br>}</pre><p>JavaScript will remove the allocated memory once the function was called. But above the code, there is no way for GC to collect the memory of “domObjects”, since it is binded to event listeners. If you want to remove these memories, you can manually delete them.</p><pre>function run(){<br> var domObjects = $(&quot;.myClass&quot;);<br> domObjects.click(function(){<br> if(domObjects){<br>  domObjects.addClass(&quot;.myOtherClass&quot;);<br>  domObjects = null;<br> }<br> });<br>}</pre><p><strong>3. String Concatenation</strong></p><p>It sounds strange, but string concatenation takes an extra memory. So avoid string concatenation and use template literal instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*KyhoxQqg_30AK1GZ3Gs6lg.png" /></figure><p><strong>4. Avoid new objects</strong></p><p>The new memory is allocated for new objects, array, etc. Try to find a way to reduce that.</p><p>Let us see an example with jQuery,</p><p>When never you use jQuery it will increase the memory in the heap, so we can avoid using jQuery chaining methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*Hckfu5jid0GeXDod9cxBZA.png" /></figure><p><strong>6. JSON Parse</strong></p><p>When your application, is render based on the JSON during page load, then consider using JSON.stringify and JSON.parse to process those data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*nxZURd6L4tRTnNOvs_EnCw.png" /></figure><p>More info: <a href="https://v8.dev/blog/cost-of-javascript-2019#json">https://v8.dev/blog/cost-of-javascript-2019#json</a></p><p><strong>7. Avoid try-catch</strong></p><p>Try-catch allocates more memory than if checks. But try-catch is necessary for most application, if you analyse properly you can change those into try-catch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*WPt1KeaAR_e85KDsamudLA.png" /></figure><p>Please take a look at this issue,</p><p>An interesting memory leak issue caused by the try-catch in the node js environment. You will get some knowledge about try-catch and memory leaks</p><p><a href="https://github.com/nodejs/node/issues/35048">https://github.com/nodejs/node/issues/35048</a></p><p><strong>8. New window</strong></p><p>While working on a new window please unset the reference variable after the window detached.<br>When closing the window, only minor GC is called so only a few memory blocks are cleared.</p><p>If you want to check the used JSHeap Memory, enter this code on your console.</p><pre><strong>performance. memory.usedJSHeapSize</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ixg_47qwCATt586HudgYqA.png" /></figure><p><strong>9. Callbacks</strong></p><p>If the events that callbacks at very high frequency, consider avoiding it.</p><p>Let us take an example with scroll.</p><p>When you bind a scroll event to the window, whenever the user scrolls down/ scrolls up, the callback will be called. But the problem here is that the callback is called at a very high frequency. You can avoid those using debounce or throttle functions.</p><p>An excellent article about debouncing and throttle.</p><p><a href="https://css-tricks.com/the-difference-between-throttling-and-debouncing/">The Difference Between Throttling and Debouncing | CSS-Tricks</a></p><p><strong>Thank you for reading! </strong>If you liked this, consider <a href="https://twitter.com/NaveenDA_">following me on Twitter</a>, and sharing the article with your developer friends.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f07ccd544190" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-memory-management-works-in-javascript-f07ccd544190">How Memory Management Works in JavaScript</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[A Detailed Guide to Using Axios in Your React App]]></title>
            <link>https://javascript.plainenglish.io/a-detailed-guide-to-using-axios-in-your-react-app-7396f79fb4c2?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7396f79fb4c2</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Sun, 23 May 2021 18:17:33 GMT</pubDate>
            <atom:updated>2021-05-23T18:17:33.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uu1eCopfZ5grgzVuIesQVw.png" /></figure><h4><strong>Introduction</strong></h4><p>React is not a full-fledged framework so it doesn’t care a lot about things like routing, network call, etc.</p><p>In the React environment we have plenty of options for pretty much everything. For the network also we have plenty of options like fetch ,axios , react-http-client , etc.</p><p>Among others, the Axios provides plenty of features like global-config , Interceptors , better error handlers, etc.</p><h4>Axios</h4><p>Axios is the promise-based HTTP client for the browser and Node.js. Axios provides a lot of features to make the HTTP network call for your React application.</p><h4>Browser support</h4><p>Axios have excellent browser support including IE11. So it will sort out a lot of browser-based network issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*P_PVf9gm1jH81LCFQbbFog.png" /><figcaption><a href="https://saucelabs.com/open_sauce/build_matrix/axios.svg">https://saucelabs.com/open_sauce/build_matrix/axios.svg</a></figcaption></figure><p>See the report on the sauce: <a href="https://saucelabs.com/u/axios">https://saucelabs.com/u/axios</a></p><h4>Installation:</h4><p>Install the Axios using npm: npm install axios</p><p>Site: <a href="https://axios-http.com/">https://axios-http.com/</a></p><h4>Create an Empty Project</h4><p>We are going to create use <a href="https://create-react-app.dev/">Create-React-App</a> and make the necessary changes you want: npx create-react-app <strong>react-simple-http</strong>.</p><p>Now you get this page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*slRBf5d5DWmOXBSd.png" /></figure><p>We will make an API call to the JSON Placeholder Server.</p><p>In the App.jsx :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/442f6643e2f3197977c64800d72fb365/href">https://medium.com/media/442f6643e2f3197977c64800d72fb365/href</a></iframe><p>In this code, you may notice that we are accessing the response data via res.data but in the response, it is an array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uae3lgZd-u_42B26kSThWQ.png" /></figure><p>Because the Axios will automatically parse the response and assign the data in the data key. And also it will provide a lot of information in the response object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08faa777b8843da014e54dddcea1748b/href">https://medium.com/media/08faa777b8843da014e54dddcea1748b/href</a></iframe><p>The above example is a very simple example, now we will look at the real-world application-specific problems like:</p><ol><li><strong>How to add auth token in the header for every request?</strong></li><li><strong>How to stop the pending request, while exiting from the page/component?</strong></li><li><strong>How to handle error in react js with Axios?</strong></li><li><strong>How to handle CSRF in the Axios?</strong></li></ol><h4>Authorization</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*oAJLwdLZsfQheCaO" /><figcaption><a href="https://unsplash.com/photos/Vp3oWLsPOss">https://unsplash.com/photos/Vp3oWLsPOss</a></figcaption></figure><p>In the real world application, every request must contain the auth-token for the authorization. In Axios, we can add the auth header for every request using <a href="https://axios-http.com/docs/interceptors">Axios-interceptor</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64998267f0563e5c020370a1e16f3874/href">https://medium.com/media/64998267f0563e5c020370a1e16f3874/href</a></iframe><p>This code will add the Authorization header for every request if the token is available. In Login/Sign-up pages we don’t need to send them Authorization to the server. On that pages, delete the local storage token if it is available.</p><h4>Abort/Cancel Request</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*xCIg0g9Mj65ymXpb" /><figcaption><a href="https://unsplash.com/photos/IqB5MPcQp6k">https://unsplash.com/photos/IqB5MPcQp6k</a></figcaption></figure><p>If the component is destroyed, we should cancel all the pending network call made by that particular component. In Axios, we can abort/cancel by using the <a href="https://axios-http.com/docs/cancellation">Axios-Cancellation</a>.</p><p>By Using the Axios cancel token, we can cancel the pending request.</p><pre>const cancelTokenSource = axios.CancelToken.source();<br><br>axios.get(&#39;/user/12345&#39;, {<br>  cancelToken: cancelTokenSource.token<br>});<br><br>// Cancel request<br>cancelTokenSource.cancel();</pre><p>The above example is the simplest use of the Axios-cancellation.</p><p>We can implement the Axios-cancellation in 3 simple steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d860c27691e344ad6fd51b58efdf611/href">https://medium.com/media/9d860c27691e344ad6fd51b58efdf611/href</a></iframe><p>I have added comments for those 3 simple steps.</p><h4><strong>Error Handling</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*k6xEt80u_Xj3-YmK" /><figcaption><a href="https://unsplash.com/photos/bMvuh0YQQ68">https://unsplash.com/photos/bMvuh0YQQ68</a></figcaption></figure><p>In the real world, every application uses some common rule like “If the response header contains 401 then redirects to the login page, etc”. For that, we need to handle the application level.</p><pre>axios.interceptors.response.use(undefined, function (error) {</pre><pre><em> // Handle you error</em></pre><pre> return Promise.reject(error);</pre><pre>});</pre><p>The above code is the simplest usage of Axios-interceptors for the global error handler but in the real world, an application needs to handle a lot in both production and development modes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0bf0e6d21e214c2f213ddf12320e113/href">https://medium.com/media/c0bf0e6d21e214c2f213ddf12320e113/href</a></iframe><p>This code will redirect to the login page if the response status code is 401 and shows the console error only in the development mode and shows an alert in both production and development modes.</p><h4>CSRF Token</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*yvvWIIlbqnuz2SHY" /><figcaption><a href="https://unsplash.com/photos/QozzJpFZ2lg">https://unsplash.com/photos/QozzJpFZ2lg</a></figcaption></figure><p>If you using a high-level web framework like Laravel, Django, etc. We might need to send the CSRF token along with the request data. Axios is having default support for the CSRF token.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc1858b884e8e30dcbc2ce3ce0291f61/href">https://medium.com/media/cc1858b884e8e30dcbc2ce3ce0291f61/href</a></iframe><p>You have any doubts about using Axios in your react application, please leave it in the comments.</p><p><strong>Thank you for reading! </strong>If you liked this, consider <a href="https://twitter.com/NaveenDA_">following me on Twitter</a>, and sharing the article with your developer friends. 🐋</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7396f79fb4c2" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/a-detailed-guide-to-using-axios-in-your-react-app-7396f79fb4c2">A Detailed Guide to Using Axios in Your React App</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 Resources for the Front-End Development]]></title>
            <link>https://javascript.plainenglish.io/the-ultimate-resources-for-the-front-end-development-1abf471725d5?source=rss-d5a923ddb25b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1abf471725d5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Naveen DA]]></dc:creator>
            <pubDate>Mon, 17 May 2021 06:33:26 GMT</pubDate>
            <atom:updated>2021-05-17T06:33:26.185Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6hiw9pLlrzftvX1btg_cw.png" /></figure><h3>Introduction</h3><p>I have 5+ years of experience in the professional web development environment. For the past 8 years, I have collected plenty of websites/tools, which is improved my productivity and reduce my work stress by doing smart work.</p><p>In this article, I am sharing the list of websites, that I personally use to improve my productivity. I am not going to say, these are the best website out there to improve web development but it helps a lot to improve my web development carrier.</p><p>In the new Information Era, data is considered as the gold/oil, so if you have data then eventually you became a wealthier person when compared to your college colleagues</p><p><strong>Please create your own list of websites</strong> that improve your productivity and also share those lists with the world so that others can gain benefit from the links and they might suggest some of the sites you may not know or better site from your listed sites.</p><p>Bookmark this notion URL, I will constantly update the links in the upcoming dates.</p><p><a href="https://www.notion.so/naveenda/Ultimate-Resource-for-Web-Development-a59f7f89efe446d8a355b12e7ebc97ce">Ultimate Resource for Web Development</a></p><p>I often read some of the posts like “<strong>200+ resources for the web development</strong>”, but believe me, you never going to use all of that website in your life. The following lists contain only 48 and which collected over 8 years(including my college days and professional carrier days), you should add the website to your personal list only if you used that website and it improves your productivity.</p><h4>General</h4><p><strong>1. </strong>CSS-Tricks — <a href="https://css-tricks.com/">https://css-tricks.com/</a></p><p><strong>2.</strong> CSS Tutorial — <a href="https://www.w3schools.com/css/">https://www.w3schools.com/css/</a></p><h4>Inspiration</h4><p><strong>3. </strong>Social media for designers owned by Adobe — <a href="https://www.behance.net/">https://www.behance.net/</a></p><p><strong>4. </strong>One of the best Social for Designers — <a href="https://dribbble.com/">https://dribbble.com/</a></p><p><strong>5.</strong> Provide Inspiration by using the real website — <a href="https://bestwebsite.gallery/">https://bestwebsite.gallery/</a></p><p><strong>6. </strong>Provide Inspiration by using the real website — <a href="https://www.awwwards.com/">https://www.awwwards.com/</a></p><p><strong>7. </strong>CSS Gallery for Web Design Inspiration — CSS Nectar — <a href="http://cssnectar.com/">http://cssnectar.com/</a></p><h4>Illustration</h4><p><strong>8. </strong>Open source illustrations — <a href="https://undraw.co/">https://undraw.co/</a></p><p><strong>9.</strong> A massive library of free 3D shapes — <a href="https://www.shapefest.com/">https://www.shapefest.com/</a></p><p><strong>10. </strong>High-Quality 3D illustrations — <a href="https://www.figma.com/community/file/890095002328610853">https://www.figma.com/community/file/890095002328610853</a></p><p><strong>11.</strong> Character Builder — <a href="https://sapiens.ui8.net/">https://sapiens.ui8.net/</a></p><p><strong>12.</strong> Open source illustrations kit — <a href="https://illlustrations.co/">https://illlustrations.co/</a></p><h4>Color</h4><p><strong>13. </strong>The super fast color schemes generator — <a href="https://coolors.co/">https://coolors.co/</a></p><p><strong>14.</strong> Beautiful colored gradients — <a href="https://uigradients.com/#Zinc">https://uigradients.com/#Zinc</a></p><p><strong>15. </strong>The Best Gradient Sites All in One Place — <a href="https://cssgradient.io/gradient-backgrounds/">https://cssgradient.io/gradient-backgrounds/</a></p><h4>Generator</h4><p><strong>16.</strong> Box Shadow CSS Generator — <a href="https://cssgenerator.org/box-shadow-css-generator.html">https://cssgenerator.org/box-shadow-css-generator.html</a></p><p><strong>17.</strong> Capsize for Google Font — <a href="https://seek-oss.github.io/capsize/">https://seek-oss.github.io/capsize/</a></p><p><strong>18.</strong> Create SVG waves for your design — <a href="https://getwaves.io/">https://getwaves.io/</a></p><p><strong>19.</strong> Make SVG shapes for your design — <a href="https://www.blobmaker.app/">https://www.blobmaker.app/</a></p><p><strong>20.</strong> Easing Gradients — <a href="https://larsenwork.com/easing-gradients/#editor">https://larsenwork.com/easing-gradients/#editor</a></p><p><strong>21.</strong> CSS Duotone Generator for Images — <a href="https://cssduotone.com/">https://cssduotone.com/</a></p><h4>Images</h4><p><strong>22.</strong> Google for colors — <a href="https://picular.co/">https://picular.co/</a></p><p><strong>23.</strong> High-Quality free images — <a href="https://unsplash.com/">https://unsplash.com/</a></p><p><strong>24.</strong> Free textures for your web project — <a href="https://www.toptal.com/designers/subtlepatterns/">https://www.toptal.com/designers/subtlepatterns/</a></p><p><strong>25.</strong> PatternPad — Create beautiful patterns for presentations, social media or branding. — <a href="https://patternpad.com/">https://patternpad.com/</a></p><h4>Icons</h4><p><strong>26.</strong> Flaticon, the largest database of free vector icons — <a href="https://www.flaticon.com/">https://www.flaticon.com/</a></p><p><strong>27.</strong> Free icon — <a href="https://freeicons.io/">https://freeicons.io/</a></p><p><strong>28.</strong> SVG Colorizer, colorize SVG icons and SVG vectors automatically — <a href="https://www.iconshock.com/svg-color/">https://www.iconshock.com/svg-color/</a></p><h4>Fonts</h4><p><strong>29.</strong> Google Fonts — <a href="https://fonts.google.com/">https://fonts.google.com/</a></p><p><strong>30.</strong> Preview 800+ Google Fonts on top of your own designs, without having to download them first. — <a href="https://fontflipper.com/">https://fontflipper.com/</a></p><p><strong>31.</strong> Free Typography Scanner — <a href="https://typoscan.com/">https://typoscan.com/</a></p><p><strong>32.</strong> Free Fonts | 79,000+ Font Downloads — <a href="https://www.fontspace.com/">https://www.fontspace.com/</a></p><h4>Performance</h4><p><strong>33.</strong> CSSO — CSS optimizer — <a href="https://css.github.io/csso/csso.html">https://css.github.io/csso/csso.html</a></p><h4>Checklist</h4><p><strong>34. </strong>✨ Your best Front-End Tool ✨ — <a href="https://frontendchecklist.io/">https://frontendchecklist.io/</a></p><h4>Chrome Plugin</h4><p><strong>35.</strong> Zoho Annotator — <a href="https://chrome.google.com/webstore/detail/zoho-annotator/dmlmcpcjndojhbflolmdgfpojnjfdlbj?hl=en">https://chrome.google.com/webstore/detail/zoho-annotator/dmlmcpcjndojhbflolmdgfpojnjfdlbj?hl=en</a></p><p><strong>37.</strong> ColorZilla — <a href="https://chrome.google.com/webstore/detail/colorzilla/bhlhnicpbhignbdhedgjhgdocnmhomnp?hl=en">https://chrome.google.com/webstore/detail/colorzilla/bhlhnicpbhignbdhedgjhgdocnmhomnp?hl=en</a></p><p><strong>38. </strong>VisBug — <a href="https://chrome.google.com/webstore/detail/visbug/cdockenadnadldjbbgcallicgledbeoc?hl=en">https://chrome.google.com/webstore/detail/visbug/cdockenadnadldjbbgcallicgledbeoc?hl=en</a></p><p><strong>39. </strong>Responsive Viewer — <a href="https://chrome.google.com/webstore/detail/responsive-viewer/inmopeiepgfljkpkidclfgbgbmfcennb?hl=en">https://chrome.google.com/webstore/detail/responsive-viewer/inmopeiepgfljkpkidclfgbgbmfcennb?hl=en</a></p><h4>Favourite fonts</h4><p><strong>40. </strong>Sen — <a href="https://fonts.google.com/specimen/Sen?query=sen#standard-styles">https://fonts.google.com/specimen/Sen?query=sen#standard-styles</a></p><p><strong>41.</strong> Nunito Sans — <a href="https://fonts.google.com/specimen/Nunito+Sans">https://fonts.google.com/specimen/Nunito+Sans</a></p><p><strong>42.</strong> Numans — <a href="https://fonts.google.com/specimen/Numans?query=Numans">https://fonts.google.com/specimen/Numans?query=Numans</a></p><p><strong>43.</strong> Tondocorp — <a href="http://legionfonts.com/fonts/tondocorp-bold">http://legionfonts.com/fonts/tondocorp-bold</a></p><p><strong>44.</strong> Crimson Text — <a href="https://fonts.google.com/specimen/Crimson+Text">https://fonts.google.com/specimen/Crimson+Text</a></p><p><strong>45.</strong> Quicksand — <a href="https://fonts.google.com/specimen/Quicksand#standard-styles">https://fonts.google.com/specimen/Quicksand#standard-styles</a></p><p><strong>46.</strong> Comfortaa — <a href="https://fonts.google.com/specimen/Comfortaa">https://fonts.google.com/specimen/Comfortaa</a></p><p><strong>48.</strong> Fredericka the Great- <a href="https://fonts.google.com/specimen/Fredericka+the+Great">https://fonts.google.com/specimen/Fredericka+the+Great</a></p><p><strong>Thank you for reading! </strong>If you liked this, consider <a href="https://twitter.com/NaveenDA_">following me on Twitter</a>, and sharing the article with your developer friends.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1abf471725d5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-ultimate-resources-for-the-front-end-development-1abf471725d5">The Ultimate Resources for the Front-End Development</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>