<?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: Daksh Kulshrestha</title>
    <description>The latest articles on DEV Community by Daksh Kulshrestha (@devdaksh).</description>
    <link>https://dev.to/devdaksh</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%2F399521%2Fd3325010-91cc-43e5-9c6d-a5678816c237.jpeg</url>
      <title>DEV Community: Daksh Kulshrestha</title>
      <link>https://dev.to/devdaksh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devdaksh"/>
    <language>en</language>
    <item>
      <title>Mysterious ways of JSX</title>
      <dc:creator>Daksh Kulshrestha</dc:creator>
      <pubDate>Sat, 17 Oct 2020 18:27:32 +0000</pubDate>
      <link>https://dev.to/devdaksh/mysterious-ways-of-jsx-2g7b</link>
      <guid>https://dev.to/devdaksh/mysterious-ways-of-jsx-2g7b</guid>
      <description>&lt;p&gt;I always wonder whenever I use React, why do I import React from react library whereas I never use it in my code?&lt;br&gt;
A simple Hello World could be written the following way&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myComponent(){
return &amp;lt;p&amp;gt;Hello World&amp;lt;/p&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I don't see React variable anywhere and code runs perfectly fine without any error. And when I don't import it, it throws a load of errors on my terminal window. So what's up with it?&lt;/p&gt;

&lt;p&gt;After learning JSX and it's ways, I found that since it isn't native Javascipt code, it has to be first complied into Javascript by come compiler such as Babel.&lt;/p&gt;

&lt;p&gt;The same code above then changes to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myComponent(){
React.createElement("p", null, "Hello World")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if we don't import it, React isn't in scope, the code can't run and importing it is a necessity.&lt;/p&gt;

&lt;p&gt;But that's a lot of hassle if you are making many different components right?&lt;/p&gt;

&lt;p&gt;Well React heard us and from React 17, there is no need to import React from the library since there is going to be a new helper which is going to be automatically injected at the time of compiling just like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {jsx as _jsx} from 'react/jsx-runtime';

function myComponent(){
 return _jsx("p", null, "Hello World")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you know why do we import React. That's it for the post. Thanks for sticking till the end.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>jsx</category>
    </item>
    <item>
      <title>Suspense in react</title>
      <dc:creator>Daksh Kulshrestha</dc:creator>
      <pubDate>Sun, 11 Oct 2020 14:43:31 +0000</pubDate>
      <link>https://dev.to/devdaksh/suspense-in-react-3e9c</link>
      <guid>https://dev.to/devdaksh/suspense-in-react-3e9c</guid>
      <description>&lt;p&gt;So, What is Suspense in React?&lt;/p&gt;

&lt;p&gt;A very simple way to put it is that it is used as a event listener for data fetching.&lt;/p&gt;

&lt;p&gt;Umm... what? what did you just say?&lt;/p&gt;

&lt;p&gt;Let me explain,&lt;/p&gt;

&lt;p&gt;When we would use a third party API to make calls, it takes a bit time to get the response, to tell the user that it's loading, what one would do is make a state and set it to a boolean and change it when data is fetched and use that state to display a spinner/loader.&lt;br&gt;
This seems pretty easy to do, but what happens when you're in a very big application?&lt;br&gt;
Making a state, updating it's value, showing spinner would be tedious. That's where Suspense comes into play.&lt;/p&gt;

&lt;p&gt;Suspense API knows when your data arrives, you just have to setup some boilerplate code once and you're set!&lt;/p&gt;

&lt;p&gt;Suspense knows when your data is still loading and it shows a fallback component till the time being, like a spinner or preloader for example.&lt;/p&gt;

&lt;p&gt;BEWARE! This is available in an experimental version of React, do not implement this is your production level apps.&lt;/p&gt;

&lt;p&gt;For those who'd like to play around with this, &lt;a href="https://codesandbox.io/s/shy-fast-2tzey?file=/src/index.js"&gt;here&lt;/a&gt; is a link to a codesandbox instance, fork it and experiment!&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>What is a service worker and why should you use it?</title>
      <dc:creator>Daksh Kulshrestha</dc:creator>
      <pubDate>Sun, 16 Aug 2020 13:26:55 +0000</pubDate>
      <link>https://dev.to/devdaksh/what-is-a-service-worker-and-why-should-you-use-it-5j3</link>
      <guid>https://dev.to/devdaksh/what-is-a-service-worker-and-why-should-you-use-it-5j3</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;What are service workers?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. They can do loads of tasks. The specific one we are gonna talk about is offline caching.&lt;/p&gt;

&lt;p&gt;I am just a beginner to Service Workers, read them about in depth &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do they work?
&lt;/h2&gt;

&lt;p&gt;A service worker usually mimics a caching server (from what I've understood so far). It downloads the assets used to run a webpage and then it automatically sets up a server with the static assets when you're offline. The offline version is automatically downloaded the first time you visit the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I know if they're enabled on a website?
&lt;/h2&gt;

&lt;p&gt;In most cases, the service workers render a different component than the actual sites. For instance, Twitter mobile version has a service worker set up which shows you're offline, that's pretty cool right?!&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I set it up in my website?
&lt;/h2&gt;

&lt;p&gt;They are to be found in &lt;code&gt;serviceworker&lt;/code&gt; object inside &lt;code&gt;navigator&lt;/code&gt; function in VanillaJS. Here, I'll teach you how to set them up in ReactJS. Before setting them up make sure your app runs over an HTTPS connection. Service workers can be used to hijack connections and filter responses. Powerful stuff. While you would use these powers for good, a man-in-the-middle might not. To avoid this, you can only register for service workers on pages served over HTTPS, so we know the service worker the browser receives hasn't been tampered with during its journey through the network. &lt;/p&gt;

&lt;p&gt;For setting them up in your React App built using CRA template, you need to open your src folder and make sure you don't touch the &lt;code&gt;serviceWorker.js&lt;/code&gt;. When your service worker's integrity is made sure of, open up &lt;code&gt;index.js&lt;/code&gt; and change the following line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;serviceworker.unregister()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;servieworker.register()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, it's THAT easy. I was shocked too. But if you're in the development server mode, offline caching won't work, since you're running the app locally.&lt;/p&gt;

&lt;p&gt;After when your app is in production, you can just visit the app once and forget to turn on your network connection next time you visit it. If your app has some sort of CRUD functionality with any database, you can also set it up to take the instructions and do them once you're online.&lt;/p&gt;

&lt;p&gt;This is one of the best practices of PWA. After a lighthouse report I got a PWA badge.&lt;/p&gt;

&lt;p&gt;If you stuck till here, thanks! This is my first blog post ever! It feels really great to write. Might do this more often.&lt;/p&gt;

</description>
      <category>react</category>
      <category>serviceworker</category>
      <category>offline</category>
      <category>pwa</category>
    </item>
  </channel>
</rss>
