<?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: Lakshya Khera</title>
    <description>The latest articles on DEV Community by Lakshya Khera (@lakshyabatman).</description>
    <link>https://dev.to/lakshyabatman</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%2F175200%2F6cec392e-8861-4246-b13a-6d983df2c308.png</url>
      <title>DEV Community: Lakshya Khera</title>
      <link>https://dev.to/lakshyabatman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lakshyabatman"/>
    <language>en</language>
    <item>
      <title>Pages and Blocks in DBMS</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Fri, 19 Jan 2024 23:02:02 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/pages-and-blocks-in-dbms-3k78</link>
      <guid>https://dev.to/lakshyabatman/pages-and-blocks-in-dbms-3k78</guid>
      <description>&lt;p&gt;Hey there! I'm not so active here cause I don't write things that often, but here we are.&lt;/p&gt;

&lt;p&gt;Been spending a lot of time around databases and everything around them, so I wanted to understand how data gets read and it's crazy how everything is orchestrated.&lt;br&gt;
Usually pages and blocks are called interchangeably which pissed me off. &lt;/p&gt;

&lt;p&gt;Disclaimer: I'm not an expert on this subject and might make mistakes. &lt;/p&gt;

&lt;p&gt;We'll consider a scenario where we're dealing with a Relational Database (eg: Postgres)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Table row is stored as tuples in disk&lt;/strong&gt;&lt;br&gt;
Remember this, what I mean by tuple is just an array of your entries in a row. &lt;/p&gt;

&lt;p&gt;But of course, you can't store all these rows as it is on disk. So these rows are bundled together in Pages (database)&lt;/p&gt;

&lt;p&gt;A page can have a bunch of rows next to each other with increasing order of IDs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fioxxddnnxd0l27u9ewbd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fioxxddnnxd0l27u9ewbd.png" alt="How tuples stored in a page"&gt;&lt;/a&gt;&lt;br&gt;
Let's not waste time around the technicals of the page.&lt;/p&gt;

&lt;p&gt;Now whenever you read a row, you're fetching a whole page! (It's mainly due to efficiency. Disk I/O operations are expensive (time-consuming)) and posts this page in its cache (RAM) so in case if you re-read it you don't have to search the disk.&lt;/p&gt;

&lt;p&gt;-- Easy till here --&lt;/p&gt;

&lt;p&gt;Now storing this page on disk requires more work, we can't just store all pages as it is cause OS handles a lot of other things (READ about fragmentation) &lt;/p&gt;

&lt;p&gt;So these pages ( end up breaking up into smaller chunks into a block (around 2kb).&lt;/p&gt;

&lt;p&gt;Block is a logical unit of data in OS, in other words, OS tells with data as blocks. So it's part of file system jobs whenever to combine all these chunks of blocks into a page/file. &lt;/p&gt;

&lt;p&gt;-- Still easy -- Cause we're not deep diving it. &lt;/p&gt;

&lt;p&gt;But this physical disk? In that realm there are no blocks, but pages or sectors. &lt;/p&gt;

&lt;p&gt;So There is a module called Disk Controller which puts these blocks into a disk and it's their job to take care of everything. &lt;br&gt;
Here in simple terms, this controller maintains an LBA (Logical Block address) to Physical address mapping. &lt;/p&gt;

&lt;p&gt;And on fetching this gets cached in the File system.&lt;/p&gt;

&lt;p&gt;--- That's it --&lt;/p&gt;

&lt;p&gt;I haven't deep-dived on things work but I suggest you should.&lt;br&gt;
Feel free to reach out, and follow my socials!&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>Types of scans in database</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Wed, 13 Sep 2023 20:23:14 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/types-of-scans-in-database-3j79</link>
      <guid>https://dev.to/lakshyabatman/types-of-scans-in-database-3j79</guid>
      <description>&lt;p&gt;Here is a micro blog on types of scans in database, this is something which stays under the hood for most of us but it's a good idea to know what happens.&lt;/p&gt;

&lt;p&gt;So whenever we fetch something from our db there are three ways for db engine to search the data based on few conditions.&lt;/p&gt;

&lt;p&gt;Let's consider an example,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Employees(&lt;br&gt;
   id int primary key not null,&lt;br&gt;
   name text not null,&lt;br&gt;
   department text,&lt;br&gt;
   age int not null&lt;br&gt;
);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I have a employees table and there are lets say there are 1 million rows and I decided to get those employees whose age is between 28 to 41. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;select * from employees where age&amp;gt;=28 and age&amp;lt;=41;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As in this case db has to go through each row one by one and check if the row satisfies the condition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TOO SLOWW&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What if I have an index on age.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE INDEX age_idx on Employees(age);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now I have a structure apart from actual db data where I can lookup from and then retrieve those data which satisfies the condition. This is index scan.&lt;/p&gt;

&lt;p&gt;Easy and fast? What if 90% of my data satisfies this condition or maybe I want those employees who belong to IT department.💀&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select * from employees where age&amp;gt;=28 and age&amp;lt;=41 and department='IT';`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It'll be very slow to retrieve from heap(actual data) one by one.&lt;/p&gt;

&lt;p&gt;Here comes bitmap scan, in this case db engine creates a bitmap, it's an array where indices refers to row and the values can be &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;. &lt;code&gt;1&lt;/code&gt; means this row needs to be fetched and &lt;code&gt;0&lt;/code&gt; means nope.&lt;/p&gt;

&lt;p&gt;The bitmap gets created first and then all data gets fetched at once. It's fast!&lt;/p&gt;

&lt;p&gt;So whats the difference between bitmap and index scan.&lt;/p&gt;

&lt;p&gt;Index scan is very efficient when the filtered data is very small and specific so we can quickly fetch from index one by one.&lt;/p&gt;

&lt;p&gt;Bitmap scan can be helpful when we have more conditions and there are too many rows which needs to be fetched. &lt;br&gt;
A great example here is let's say we have index on department and age column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create index age_idx on Employees(age);
create index dept_idx on Employees(department);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to fetch those rows where age is between &lt;code&gt;28&lt;/code&gt; and &lt;code&gt;41&lt;/code&gt; and also the department is &lt;code&gt;IT&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here we can create bitmaps on the both indexes and run an AND operation over both bitmaps to get those rows which satisfies both of the conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thats it!&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Sorry for such long post, wanted to keep it a micro blog but I failed :P&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Advance CSS resources</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Tue, 27 Oct 2020 14:10:26 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/advance-css-resources-4pa6</link>
      <guid>https://dev.to/lakshyabatman/advance-css-resources-4pa6</guid>
      <description>&lt;p&gt;So recently I realised that I am still little weak in CSS, when it comes to advanced concepts, including animations, building very complex pages and all. I looked over the internet and all I find the same things taught by everyone. &lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;nth-child&lt;/li&gt;
&lt;li&gt;::before , ::after
etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any advice where should I look over and what should I do.&lt;/p&gt;

&lt;p&gt;Thank you! &lt;/p&gt;

</description>
      <category>help</category>
    </item>
    <item>
      <title>Cheatsheet to React Lifecycle hooks Part-3</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Thu, 22 Oct 2020 18:08:01 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-3-3cg0</link>
      <guid>https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-3-3cg0</guid>
      <description>&lt;p&gt;So, here is the final blog of the series, hope you've learned something out it.&lt;/p&gt;

&lt;p&gt;Anyway, links to my previous blogs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-1-597d"&gt;Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-2-l1b"&gt;Part 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let's end with lifecycle hooks in &lt;strong&gt;functional components&lt;/strong&gt; and they're pretty clean and easy to grasp.&lt;/p&gt;

&lt;p&gt;To add these lifecycle hooks we'll use &lt;code&gt;useEffect&lt;/code&gt; from &lt;code&gt;react&lt;/code&gt; package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in our functional component, we can use it this way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Use effect go brrr!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's pretty easy to understand, that the callback function will be executed when the hook is trigged.&lt;br&gt;
&lt;strong&gt;But when will it be executed?&lt;/strong&gt;&lt;br&gt;
In this case, in all events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How we can utilise to trigger on specific change ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the previous example, if I add a second argument of array type then the hook will be triggered whenever the element placed in that array is changed and this element can be props, state or anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Use effect go brrr!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the hook will only be triggered whenever &lt;code&gt;props.a&lt;/code&gt; and &lt;code&gt;state.b&lt;/code&gt; updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, what about when we want the hook to trigger on mounting only&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can place an empty array in the second argument and this will make sure the hook only runs on mounting.&lt;br&gt;
This tells React that your effect doesn’t depend on any values from props or state, so it never needs to re-run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Use effect go brrr!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Okay! We can do this, don't give up!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;What about cleanup or when the component unmounts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, in our effect, we can return a function and it'll run &lt;strong&gt;after&lt;/strong&gt; the &lt;strong&gt;first execution of the effect&lt;/strong&gt; and &lt;strong&gt;before&lt;/strong&gt; every other render cycle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/swrTFeuOt2v6g/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/swrTFeuOt2v6g/source.gif" width="200" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah, &lt;strong&gt;it is what it is&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But we can utilise it in a lot of ways! Seriously!&lt;br&gt;
In our previous explanation, this return function will be called before &lt;code&gt;useEffect&lt;/code&gt; method except the first when &lt;code&gt;useEffect&lt;/code&gt; is called, which means we can use it for cleanup work. ¯\_(ツ)_/¯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what about the case when [] is passed in second argument&lt;/strong&gt;, which means in this case the return method will be executed when the component unmounts!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/tlGD7PDy1w8fK/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/tlGD7PDy1w8fK/source.gif" width="500" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, this is the end! I'm tired now but yeah don't let my hard work fade away. Make sure you read the docs and try things out! &amp;lt;3 &lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Cheatsheet to React Lifecycle hooks Part-2</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Thu, 22 Oct 2020 16:02:46 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-2-l1b</link>
      <guid>https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-2-l1b</guid>
      <description>&lt;p&gt;Hey there, hopefully, you've read the first part of the series and if not go and &lt;a href="https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-1-597d"&gt;read&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, now we're discussing ** Update lifecycle hooks on props and state change.** &lt;br&gt;
So, let's point out in what ways you can update a component,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change state &lt;/li&gt;
&lt;li&gt;Change prop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So react provides several hooks which can be accessed to handle these changes, so we're going to discuss each of them one by one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/CjmvTCZf2U3p09Cn0h/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/CjmvTCZf2U3p09Cn0h/source.gif" width="592" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;getDerivedStateFromProps&lt;/strong&gt;, as discussed in &lt;a href="https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-1-597d"&gt;Part-1&lt;/a&gt;, this hook runs in both mounting and updating cycle, and it takes &lt;code&gt;props and state&lt;/code&gt; as the arguments so the developer can update state according to change in props and most importantly it should return an object to update the state, or null to update nothing also make sure not to do &lt;code&gt;side-effects&lt;/code&gt; here.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;getDerviedStateFromProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="c1"&gt;//update the state if required &lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="c1"&gt;//or null&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;shouldComponentUpdate&lt;/strong&gt;, so here is a great hook that we can utilise to improve performance of our application, let's say we props get updated but we don't want to re-render the component for some reasons, so here we can utilise this hook and return a boolean &lt;code&gt;true to continue updating, false to abort&lt;/code&gt;, this way we can reduce unnecessary re-rendering thus improving performance. Also, don't do &lt;code&gt;side-effects&lt;/code&gt; here.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, interesting takeaway, the &lt;code&gt;nextState&lt;/code&gt; comes from the &lt;code&gt;getDerviedStateFromProps&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;shouldComponentUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nextProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;nextState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/*Some checks*/&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;render&lt;/strong&gt;, as we discussed we know what we're gonna do here &lt;strong&gt;Prepare your JSX&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;love&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update child components&lt;/strong&gt;, nothing here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;getSnapshotBeforeUpdate&lt;/strong&gt;, this is an interesting hook, here we get last-minute snapshot of the component before the update, which means previous props and state which are passed as arguments in it so that we can do some computation if required. A snapshot value (or null) should be returned.&lt;br&gt;
The best use case is we can use it to store user position in an application, so after the update, we can scroll it to that position automatically hence improving user experience.&lt;br&gt;
Still not a goot place for side effects.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;getSnapshotBeforeUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prevState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Code here &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;componentDidUpdate&lt;/strong&gt;, reaching the end, this is the best time for side-effects because our application is updated and we do anything we want.
Protip: Try to keep side-effects async, so it won't mess up with react lifecycle. Also, don't update the state here, it'll cause re-render.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;componentDidUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prevState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What about when the component unmounts or get destroyed?&lt;/strong&gt;&lt;br&gt;
Here we can use &lt;code&gt;componentWillUnmount&lt;/code&gt;, this will be executed just before the component is unmounted and this is best for cleanup work,&lt;strong&gt;don't update state here cause it'll never be re-render&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/j1Xyt3DHfJcmk/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/j1Xyt3DHfJcmk/source.gif" width="328" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here it is the end of part 2, hope you enjoyed it! I'm extremely tired so will write part 3 later. Anyway happy coding! Please like and follow &amp;lt;3 it'll motivate me. &lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Cheatsheet to React Lifecycle hooks Part-1</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Thu, 22 Oct 2020 13:31:40 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-1-597d</link>
      <guid>https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-1-597d</guid>
      <description>&lt;p&gt;I know this is the topic you can find anywhere so what's the point of writing it again?&lt;br&gt;
What if I tell you this is the only post or article you would need to understand react lifecycle hooks and for revision as well.&lt;/p&gt;

&lt;p&gt;So, here is the backstory I need to brush my knowledge in React and I started revising lifecycle so I thought I should write a blog and if I need to come back to something I can just look over it.&lt;/p&gt;

&lt;p&gt;So, I'm writing 3 part tutorials on React lifecycle hooks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Component creation hooks in class-based components&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component update hooks on props and state change in class-based components&lt;/strong&gt; &lt;a href="https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-2-l1b"&gt;Link&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React hooks in functional components&lt;/strong&gt; &lt;a href="https://dev.to/lakshyabatman/cheatsheet-to-react-lifecycle-hooks-part-3-3cg0"&gt;Link&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is React lifecycle hooks?:
&lt;/h2&gt;

&lt;p&gt;So every react component goes through a lifecycle(creation, rendering, updating) and react emits certain methods which can be overloaded, so we can(as a developer) use it for anything(Spoiler: with some restrictions).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/UnTC9o2HMyUta/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/UnTC9o2HMyUta/source.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As in every other tutorial, I'll show you this cool flow diagram! :D &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2Au8hTumGAPQMYZIvfgQMfPA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2Au8hTumGAPQMYZIvfgQMfPA.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is lifecycle flow for a class component (yes, now functional components have lifecycle hooks as well &lt;code&gt;npm update react&lt;/code&gt; please.)&lt;/p&gt;

&lt;p&gt;Before diving, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Side effects are methods which have no relation with the application as it calls 3rd party libraries or API which lives outside the application ecosystem. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Component creation
&lt;/h2&gt;

&lt;p&gt;So, when a component is created it goes through some phases including &lt;code&gt;constructor&lt;/code&gt; to &lt;code&gt;ComponentDidMount&lt;/code&gt; and we'll be discussing every method in detail and what kind of action you should take in it. Bear with me :D&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First &lt;code&gt;constructor&lt;/code&gt; is called, it takes props as its argument and injects it to the component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Do&lt;/strong&gt;: Prepare state, according to props if you want so.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't&lt;/strong&gt;: Side Effects or anything which might take the time or fail as it'll mess up with the application or impacts performance.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Then, &lt;code&gt;getDerivedStateFromProps&lt;/code&gt; is called, this is called whenever props are changed, so it exists both in &lt;strong&gt;creation and update cycle&lt;/strong&gt;, as it's doesn't depend on the component instance we use &lt;code&gt;static&lt;/code&gt; before it (i.e &lt;code&gt;static getDerivedStateFromProps&lt;/code&gt;). It should return an object to update the state, or null to update nothing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Do&lt;/strong&gt;: Sync your state according to props.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't&lt;/strong&gt;: Side effects&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Now &lt;code&gt;render&lt;/code&gt; method is called, and this is the method which returns JSX so what you should do in it? Structure your JSX nothing else!&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Now Childs Components are rendered! The same cycle is followed in children and so on.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Now &lt;code&gt;ComponentDidMount&lt;/code&gt; is called, everything is done! Congratulations! Now you can call side effects but don't update state it'll re-render the component.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;That's pretty it! Hope you enjoyed it :D, please like and add me up on Twitter and Linkedin it does motivate me a lot. Ps: I need motivation these days :')&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ui1hpJSyBDWlG/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ui1hpJSyBDWlG/source.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/state-and-lifecycle.html" rel="noopener noreferrer"&gt;React Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Vue + Typescript = 🔥</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Wed, 22 Apr 2020 04:55:03 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/vue-typescript-4eko</link>
      <guid>https://dev.to/lakshyabatman/vue-typescript-4eko</guid>
      <description>&lt;p&gt;So, I wrote an article about Vue using Typescript on Medium &lt;a href="https://medium.com/@lakshya.khera/vue-typescript-3bf2a5b38532"&gt;link&lt;/a&gt;, so thought to write about it here.&lt;/p&gt;

&lt;p&gt;I am a huge fan of Vue and recently I joined as an intern at an organisation where they're using Vue + Typescript so after a week of hustle, I finally have an idea how to get started.&lt;/p&gt;

&lt;p&gt;So Vue + typescript works on class-based components, and use decorators to add functionality in class, to get started let's build a simple component.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We used Component decorative from 'vue-property-decorator' and used it over the class which extends Vue and exported it.&lt;/p&gt;

&lt;p&gt;What about the state, well we can add an attribute and it will work as an state property.&lt;/p&gt;

&lt;p&gt;Now let's add props and a child component.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here, we used Prop decorator and simply added to an attribute in the component, and with the power of typescript's static typing, I can add datatype as well.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, in the component decorator, we can add components property where child components can be registered.&lt;/p&gt;

&lt;p&gt;I talked briefly talked over other decorators over my medium article, and here I'm adding a link for a practice project I build using vue + typescript. &lt;a href="https://github.com/lakshyabatman/vue-projects-on-ts"&gt;Link&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>vue</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Twiliohackathon Project - ConnectShop</title>
      <dc:creator>Lakshya Khera</dc:creator>
      <pubDate>Fri, 03 Apr 2020 21:26:16 +0000</pubDate>
      <link>https://dev.to/lakshyabatman/twiliohackathon-project-connectshop-61</link>
      <guid>https://dev.to/lakshyabatman/twiliohackathon-project-connectshop-61</guid>
      <description>&lt;h2&gt;
  
  
  What I want to build
&lt;/h2&gt;

&lt;p&gt;Hey, this is my first blog for Twiliohackathon, and our first milestone is brainstorming an idea, UI/UX designs and codebase structure.&lt;/p&gt;

&lt;p&gt;Before talking about the idea, let me share you about me and my team partner Uphaar, we both live in same city and due to lockdown we're facing issues like not access to the market or nearby general store because most of the time they're closed and we're not allowed to go outside unless necessary. &lt;/p&gt;

&lt;p&gt;To tackle this, we thought to build an application which can connect consumers to shopkeepers so they can track which nearby shops are opened and contact them and also tells consumer is there rush in the shop or not so the user can go out accordingly.&lt;/p&gt;

&lt;p&gt;We can integrate Twilio in the application in the following ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding OTP verification for users.&lt;/li&gt;
&lt;li&gt;Push SMS notification for the consumer whether the shop is opened.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We decided to keep the tech stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React Native&lt;/li&gt;
&lt;li&gt;NodeJS&lt;/li&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Designs
&lt;/h3&gt;

&lt;p&gt;For now, I'm building the designs and here goes the &lt;a href="https://www.figma.com/file/9dG1Yv7Y2StuCsPN58zWVr/ConnectShop?node-id=0%3A1"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  CodeBase
&lt;/h3&gt;

&lt;p&gt;We will setup Github repository and build proper database designs for same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let me know your opinion on our idea.
&lt;/h2&gt;

&lt;p&gt;Thankyou! &amp;lt;3&lt;/p&gt;

</description>
      <category>twiliohackathon</category>
      <category>reactnative</category>
      <category>node</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
