<?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: Bunlong</title>
    <description>The latest articles on DEV Community by Bunlong (@bunlong).</description>
    <link>https://dev.to/bunlong</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%2F328374%2Fa45945f1-e2a1-4018-8a65-b0926f09bc94.png</url>
      <title>DEV Community: Bunlong</title>
      <link>https://dev.to/bunlong</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bunlong"/>
    <language>en</language>
    <item>
      <title>The Benefits of Design Principles and Design Patterns</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Mon, 29 Mar 2021 09:17:33 +0000</pubDate>
      <link>https://dev.to/bunlong/the-benefits-of-design-principles-and-design-patterns-3fg2</link>
      <guid>https://dev.to/bunlong/the-benefits-of-design-principles-and-design-patterns-3fg2</guid>
      <description>&lt;h3&gt;
  
  
  1. What is Design Principles?
&lt;/h3&gt;

&lt;p&gt;Design Principles are a set of general guidelines that are used to design and structure a class in object-oriented designing. It make code easier to understand, collaborate, extend &amp;amp; maintain.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. What is Design Patterns?
&lt;/h3&gt;

&lt;p&gt;Design Patterns is best practices to implement Design Principles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Design Principles and Design Patterns make the program easier to read, understand, extend, maintain and scalable.&lt;/p&gt;

</description>
      <category>design</category>
      <category>principles</category>
      <category>patterns</category>
    </item>
    <item>
      <title>Intro to Visual Studio Code Debug Visualizer</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Sat, 14 Nov 2020 10:29:10 +0000</pubDate>
      <link>https://dev.to/algorithmshub/intro-to-visual-studio-code-debug-visualizer-jcc</link>
      <guid>https://dev.to/algorithmshub/intro-to-visual-studio-code-debug-visualizer-jcc</guid>
      <description>&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=hediet.debug-visualizer" rel="noopener noreferrer"&gt;Debug Visualizer&lt;/a&gt; is a vscode extension for visualizing data structures while debugging.&lt;/p&gt;

&lt;h3&gt;
  
  
  Supported Languages
&lt;/h3&gt;

&lt;p&gt;These languages and debuggers are verified to work with this extension: JavaScript/TypeScript, Go, Python, C#, PHP, Java, C++, Swift, Rust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ext install hediet.debug-visualizer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;After installing this extension go to &lt;code&gt;View&lt;/code&gt; and click on &lt;code&gt;Command Palette&lt;/code&gt; (Ctrl + Shift +P) of VS Code.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fcommand-palette.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fcommand-palette.png" title="Command Palette" alt="Command Palette"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And use the command &lt;code&gt;Debug Visualizer: New View&lt;/code&gt; to open a new visualizer view.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-new-view.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-new-view.png" title="Debug Visualizer: New View" alt="Debug Visualizer: New View"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visualizer view:&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer.png" title="Debug Visualizer" alt="Debug Visualizer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then go to &lt;code&gt;View&lt;/code&gt; and click on &lt;code&gt;Command Palette&lt;/code&gt; (Ctrl + Shift +P) of VS Code again.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fcommand-palette.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fcommand-palette.png" title="Command Palette" alt="Command Palette"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And use the command &lt;code&gt;Debug Visualizer: Use Selection as Expression&lt;/code&gt; (Shift + F1) to use the currently selected text as expression in the most recently opened debug visualizer.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-use-selection-as-expression.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-use-selection-as-expression.png" title="Debug Visualizer: Use Selection as Expression" alt="Debug Visualizer: Use Selection as Expression"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Download sample JavaScript repository &lt;a href="https://github.com/hediet/vscode-debug-visualizer/tree/master/demos/js" rel="noopener noreferrer"&gt;here&lt;/a&gt; and following command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd demos/js
$ npm install
$ npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;demo_sorting.ts&lt;/code&gt; in Visual Studio Code and set breakpoint at line 69.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fvisual-studio-code-and-set-breakpoint-at-line-69.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fvisual-studio-code-and-set-breakpoint-at-line-69.png" title="Visual Studio Code and set breakpoint at line 69" alt="Visual Studio Code and set breakpoint at line 69"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then go to &lt;code&gt;Run&lt;/code&gt; and click on &lt;code&gt;Start Debugging&lt;/code&gt; (F5) of VS Code.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fstart-debugging.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fstart-debugging.png" title="Start Debugging" alt="Start Debugging"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then input the variable &lt;code&gt;array&lt;/code&gt; that you want to debug.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-input.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-input.png" title="Debug Visualizer Input" alt="Debug Visualizer Input"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Debug Visualizer show the graph as following.&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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-graph.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%2Fraw.githubusercontent.com%2Falgorithmshub%2Fintro-to-vscode-debug-visualizer%2Fmain%2Fstatic%2Fimages%2Fdebug-visualizer-graph.png" title="Debug Visualizer Graph" alt="Debug Visualizer Graph"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;p&gt;Follow us to catch the newest Algorithms articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="//www.github.com/algorithmshub"&gt;AlgorithmsHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="//www.twitter.com/algorithmshub"&gt;AlgorithmsHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="//www.linkedin.com/algorithmshub"&gt;AlgorithmsHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;FB: &lt;a href="//www.facebook.com/algorithmshub"&gt;AlgorithmsHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>tooling</category>
      <category>vscode</category>
      <category>debug</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Should I focus on Data Structures and Algorithms or Programming Languages?</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Wed, 12 Feb 2020 02:47:21 +0000</pubDate>
      <link>https://dev.to/bunlong/should-i-focus-on-data-structures-and-algorithms-or-programming-languages-1km9</link>
      <guid>https://dev.to/bunlong/should-i-focus-on-data-structures-and-algorithms-or-programming-languages-1km9</guid>
      <description>&lt;p&gt;Data Structures along with Algorithms is a core key of computer science so we should focus on both.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Structures and Algorithms
&lt;/h2&gt;

&lt;p&gt;Data Structures and Algorithms is the heart of Computer Science and it is inevitably being used in almost all domain of the computer science industry.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Arrays.binarySearch()&lt;/code&gt; method in Java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;binarySearch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;searchElement&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It does a search with a given array and searchElement. But what we usually don't know is that how binary search works internally, we end up using DSA everyday.&lt;/p&gt;

&lt;p&gt;A lot of methods/functions we use daily in any programming languages is implemented in the most efficient way using DSA.&lt;/p&gt;

&lt;h2&gt;
  
  
  Programming Languages and Frameworks
&lt;/h2&gt;

&lt;p&gt;Pretty sure we can't develop an application just using only DSA we really need some kind of programming languages, frameworks and tools to implement it.&lt;/p&gt;

&lt;p&gt;Assume that we want to build a web application it required a front-end, a back-end, and a database.&lt;/p&gt;

&lt;p&gt;At front-end can be built using some kind of scripts, programmings and tools as below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;Bootstrap, Material UI, Tailwind&lt;/li&gt;
&lt;li&gt;ReactJS, AngularJS, VueJS, PreactJS, SvelteJS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At back-end can be built using some kind of programmings and framework as below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;PHP (Laravel)&lt;/li&gt;
&lt;li&gt;Ruby (Ruby on Rails)&lt;/li&gt;
&lt;li&gt;Java (Spring)&lt;/li&gt;
&lt;li&gt;Erlang (Chicago Boss)&lt;/li&gt;
&lt;li&gt;Go (Gin)&lt;/li&gt;
&lt;li&gt;Python (Django)&lt;/li&gt;
&lt;li&gt;Node (Express)&lt;/li&gt;
&lt;li&gt;Deno&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the above points give us a clear understanding that knowing only DSA won't help us build a full-fledged application.&lt;/p&gt;

&lt;p&gt;Data Structures and Algorithms is used to make the implementation more efficient in terms of time and space. Programming Languages is used to implement and build applications and make the friendly user interface.&lt;/p&gt;

&lt;p&gt;Both are very important for developing a full-fledged and efficient application for the users.&lt;/p&gt;

&lt;p&gt;With real world example of building Google maps:&lt;/p&gt;

&lt;p&gt;Google Maps is being used by millions users. Google Maps has a very friendly UI and it is very easy to use and running so fast. But how? because the engineers at google made it so efficient by applying DSA, distributed servers, architecture and programming languages. They are really very important.&lt;/p&gt;

&lt;h2&gt;
  
  
  To be a Good Programmer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Experiences in developing various applications in various businesses using various programming languages.&lt;/li&gt;
&lt;li&gt;Have good knowledge of data structures and algorithms.&lt;/li&gt;
&lt;li&gt;Have good knowledge of database related concepts.&lt;/li&gt;
&lt;li&gt;Have good knowledge of the basic networking concepts.&lt;/li&gt;
&lt;li&gt;Have good knowledge of microservices architectures.&lt;/li&gt;
&lt;li&gt;Have concepts of making friendly user interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Technology changes fast. Don't get left behind. Learn as much as we can.&lt;/p&gt;

&lt;p&gt;Thanks for reading ❤ Say Hello! &lt;a href="https://github.com/bunlong"&gt;Github&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/bunlongvan"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/bunlongvan"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datastructures</category>
      <category>computerscience</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Why Data Structures and Algorithms?</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Mon, 10 Feb 2020 15:44:14 +0000</pubDate>
      <link>https://dev.to/bunlong/why-data-structures-and-algorithms-523f</link>
      <guid>https://dev.to/bunlong/why-data-structures-and-algorithms-523f</guid>
      <description>&lt;p&gt;Data Structures and Algorithms are some of the most essential topics for programmers, both to get a job and to do well on a job.&lt;/p&gt;

&lt;p&gt;Good knowledge of data structures and algorithms is the foundation of developing the high quality applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Algorithms?
&lt;/h2&gt;

&lt;p&gt;Basically an algorithms is a process or set of rules which is used to solve a computer problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---W-50x1G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/596/1%2Ac-75ePZfP9qra_fRzbLUNg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---W-50x1G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/596/1%2Ac-75ePZfP9qra_fRzbLUNg.png" alt="Algorithms"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Algorithms used for?
&lt;/h2&gt;

&lt;p&gt;Algorithms is used to solve a particular problem with the best approach.&lt;/p&gt;

&lt;p&gt;There are different approaches to solve a problem. Some approaches take more time and effort and some don't according to programmers knowledge and experience on how they implements the best algorithm for that particular problem.&lt;/p&gt;

&lt;p&gt;Let consider the task of searching an element in an array:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Algorithm 1: Using Linear search.&lt;/li&gt;
&lt;li&gt;Algorithm 2: Using Binary search.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Linear search and Binary search, which one is faster? To get to know the faster one you have to get your hands dirty with data structures and algorithms.&lt;/p&gt;

&lt;p&gt;Algorithm analysis (Big O Notation, Big Omega Notation, Big Theta Notation) is a technique that is used to measure the performance of the algorithms. Speed is one of the key parameters in determining the potential of an algorithm.&lt;/p&gt;

&lt;p&gt;There are some other factors like user-friendliness, security, maintainability, and usage space that determine the quality of an algorithm. Time and space complexity are metrics used to measure parameters.&lt;/p&gt;

&lt;p&gt;To apply algorithms in programming, firstly you need to pick up one of computer programming language to implement the algorithms and then apply the usage of variables, loops, make the use of jump statements as it makes algorithms run smoothly using little space of memory, or use the break to terminate the process, and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Data Structures?
&lt;/h2&gt;

&lt;p&gt;Data Structures is a particular way of organizing data in a computer so that it can be used efficiently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pPO06LbE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1100/1%2AJQQgERSZ5l0BmX99aCCWXA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pPO06LbE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1100/1%2AJQQgERSZ5l0BmX99aCCWXA.png" alt="Data Structures"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Data Structures used for?
&lt;/h2&gt;

&lt;p&gt;Data Structures is used to organize the storage and retrieval of information stored in both main memory(Known as RAM) and secondary memory(Known as Hard Disks).&lt;/p&gt;

&lt;p&gt;You know? Data Structures is a core key factor in software design.&lt;/p&gt;

&lt;p&gt;A data structure is selected or designed to store data for the purpose of applying with various algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;All the above points give you a clear understanding that how the organizing of data is really important in programmers day to day life.&lt;/p&gt;

&lt;p&gt;Data structures along with algorithms is a core key of computer science.&lt;/p&gt;

&lt;p&gt;Thanks for reading ❤ Say Hello! &lt;a href="https://github.com/bunlong"&gt;Github&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/bunlongvan"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/bunlongvan"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>datastructures</category>
      <category>algorithms</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Arrow Functions Return Rules in JavaScript</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Tue, 04 Feb 2020 14:02:45 +0000</pubDate>
      <link>https://dev.to/bunlong/arrow-functions-return-rules-in-javascript-2g3o</link>
      <guid>https://dev.to/bunlong/arrow-functions-return-rules-in-javascript-2g3o</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l4R7W_-C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/650/1%2AGG9YZmW3GEEW6FZPqS8RRQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l4R7W_-C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/650/1%2AGG9YZmW3GEEW6FZPqS8RRQ.png" alt="Arrow Functions Return Rules in JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 2 ways for returning values in arrow functions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Explicit Return&lt;/li&gt;
&lt;li&gt;Implicit Return&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Explicit Return
&lt;/h2&gt;

&lt;h4&gt;
  
  
  What is Explicit Return?
&lt;/h4&gt;

&lt;p&gt;A function is returned values using the return keyword, it’s called an explicit return.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Rules of Explicit Return
&lt;/h4&gt;

&lt;p&gt;You must use an explicit return statement in a block body.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Single-line&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;explicit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Multi-line&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;explicit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&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;h2&gt;
  
  
  2. Implicit Return
&lt;/h2&gt;

&lt;h4&gt;
  
  
  What is Implicit Return?
&lt;/h4&gt;

&lt;p&gt;A function is returned values without using the return keyword, it’s called an implicit return.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Rules of Implicit Return
&lt;/h4&gt;

&lt;p&gt;You must use an implicit return in a concise body.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Single-line&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;implicit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Multi-line&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;implicit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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;value&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Issue Returning Objects
&lt;/h4&gt;

&lt;p&gt;When using implicit returns, object literals must be wrapped in parenthesis so that the curly braces are not mistaken for the opening of the function’s body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;implicit&lt;/span&gt; &lt;span class="o"&gt;=&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="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;implicit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;implicit&lt;/span&gt; &lt;span class="o"&gt;=&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="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;implicit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// { value: 1 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Parens Rules
&lt;/h2&gt;

&lt;p&gt;Arrow functions can omit parentheses when they have exactly one parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Arrow Functions, with parentheses&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&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="c1"&gt;// Arrow Functions, without parentheses&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In all other cases (multiple parameters), the parameter(s) must be wrapped in parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Arrow Function, with parentheses&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p2&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jaketrent.com/post/javascript-arrow-function-return-rules"&gt;JavaScript Arrow Function Return Rules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eslint.org/docs/rules/arrow-parens"&gt;Eslint — arrow-parens rules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;MDN Web Docs — Arrow functions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading ❤ Say Hello! &lt;a href="https://github.com/bunlong"&gt;Github&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/bunlongvan"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/bunlongvan"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>React Component Lifecycle Hooks Cheatsheet</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Sun, 02 Feb 2020 13:44:36 +0000</pubDate>
      <link>https://dev.to/bunlong/react-component-lifecycle-hooks-cheatsheet-41c3</link>
      <guid>https://dev.to/bunlong/react-component-lifecycle-hooks-cheatsheet-41c3</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S1NFg-EJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/800/1%2AJ1OWWbEDit18yTrM0sthgA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S1NFg-EJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/800/1%2AJ1OWWbEDit18yTrM0sthgA.png" alt="React Component Lifecycle Hooks Cheatsheet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://dev.to/bunlong/react-component-lifecycle-methods-cheatsheet-23gi"&gt;React Component Lifecycle Methods Cheatsheet&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://dev.to/bunlong/react-component-lifecycle-hooks-cheatsheet-41c3"&gt;React Component Lifecycle Hooks Cheatsheet&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useEffect&lt;/code&gt;, &lt;code&gt;useRef&lt;/code&gt; and &lt;code&gt;React.memo&lt;/code&gt; are the hooks and the higher order component that allow you to replace React class component lifecycle methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  useState
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; to manage a component’s local state.&lt;br&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; to replace the need for this.state and constructor.&lt;/p&gt;

&lt;h2&gt;
  
  
  useEffect
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; to manage side effects (Ex. an API request, tracking analytics, interacting with DOM not contained inside your React app, etc).&lt;br&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; to replace the need for lifecycle methods (&lt;a href="https://dev.to/bunlong/react-component-lifecycle-methods-cheatsheet-23gi"&gt;React Component Lifecycle Methods Cheatsheet&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  useRef
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; to provide the way to access DOM nodes or HTML elements created in the render method.&lt;br&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; to helps the &lt;code&gt;useEffect&lt;/code&gt; to replaces the need for &lt;code&gt;componentDidUpdate&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  memo
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use:&lt;/strong&gt; to manage a component’s re-rendering.&lt;br&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; to replace the need for &lt;code&gt;shouldComponentUpdate&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explanation with Words and Code
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&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="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ReactLifecycleHooks&lt;/span&gt; &lt;span class="o"&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// Commonly Used Hooks&lt;/span&gt;
  &lt;span class="c1"&gt;// Purpose: Initialize state, read and update state variable.&lt;/span&gt;

  &lt;span class="c1"&gt;// The useState hook allows you to read and update a state variable.&lt;/span&gt;
  &lt;span class="c1"&gt;// The usetState function returns an array containing the current value and the function to &lt;/span&gt;
  &lt;span class="c1"&gt;// update the value.        &lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setDesc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prevCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPrevCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// The mounted variable of useRef here is used to check the component is rendered.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mounted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&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="s1"&gt;render&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// The useEffect hook takes 2 arguments, a function containing a side effect action and an array.&lt;/span&gt;
  &lt;span class="c1"&gt;// The array contains the variable(s) that you want to track.&lt;/span&gt;
  &lt;span class="c1"&gt;// When a value in the array changes, the side effect function is executed.&lt;/span&gt;

  &lt;span class="c1"&gt;// The empty array is passed to useEffect as its second argument&lt;/span&gt;
  &lt;span class="c1"&gt;// in the purpose of replacing the useEffect with componentDidMount &amp;amp; componentWillUnmount.&lt;/span&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="s1"&gt;componentDidMount&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Lifecycle: Mount immediately after render.&lt;/span&gt;
    &lt;span class="c1"&gt;// Purpose: Initialize state that requires DOM nodes, Network requests and side effects.&lt;/span&gt;
    &lt;span class="k"&gt;return&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="s1"&gt;componentWillUnmount&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="c1"&gt;// Lifecycle: Unmount.&lt;/span&gt;
      &lt;span class="c1"&gt;// Purpost: Clean up things such as event handlers, cancel network request, etc.&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="c1"&gt;// The array containing props.count is passed to useEffect as its second argument&lt;/span&gt;
  &lt;span class="c1"&gt;// in the purpose of replacing the useEffect with componentDidUpdate.&lt;/span&gt;
  &lt;span class="c1"&gt;// The useEffect is tracking the value of props.count, and when it sees a change, the side effect&lt;/span&gt;
  &lt;span class="c1"&gt;// function is executed.&lt;/span&gt;
  &lt;span class="c1"&gt;// When the side effect function executes, the logic of checking componentDidUpdate is executed.&lt;/span&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;mounted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;mounted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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="s1"&gt;componentDidUpdate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="c1"&gt;// Lifecycle: Update immediately after render.&lt;/span&gt;
      &lt;span class="c1"&gt;// Purpose: Operate on updated DOM or handle network requests.&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;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="c1"&gt;// The logic of calling function getDerivedStateFromProps.&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevCount&lt;/span&gt; &lt;span class="o"&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;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setDesc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ReactLifecycleHooksOptimization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDerivedStateFromProps&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;desc&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;setPrevCount&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;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Required&lt;/span&gt;
  &lt;span class="c1"&gt;// Code to display the component.&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;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;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Return true if you don't want it to rerender, return false if you want it to render.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shouldComponentUpdate&lt;/span&gt; &lt;span class="o"&gt;=&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;nextProps&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="s1"&gt;shouldComponentUpdate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Lifecycle: Update immediately before render.&lt;/span&gt;
  &lt;span class="c1"&gt;// Purpose: Allows developer to prevent rendering.&lt;/span&gt;
  &lt;span class="k"&gt;return&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;count&lt;/span&gt; &lt;span class="o"&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;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// The memo higher order component allows you to replace the need for shouldComponentUpdate.&lt;/span&gt;
&lt;span class="c1"&gt;// The memo higher order component takes 2 arguments, a component and a comparison function of &lt;/span&gt;
&lt;span class="c1"&gt;// prevProps and nextProps.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ReactLifecycleHooksOptimization&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ReactLifecycleHooks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shouldComponentUpdate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Rarely Used Lifecycle&lt;/span&gt;

&lt;span class="c1"&gt;// The getDerivedStateFromProps function here is created for the purpose of &lt;/span&gt;
&lt;span class="c1"&gt;// using getDerivedStateFromProps in hooks.&lt;/span&gt;
&lt;span class="nx"&gt;ReactLifecycleHooksOptimization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDerivedStateFromProps&lt;/span&gt; &lt;span class="o"&gt;=&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;prevState&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="s2"&gt;`getDerivedStateFromProps
  nextProps.count=&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;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
  prevState=&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Lifecycle: Mount and update immediately before render.&lt;/span&gt;
  &lt;span class="c1"&gt;// Purpose: When your state depends on props (should be avoided).&lt;/span&gt;
  &lt;span class="k"&gt;if&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;count&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&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;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&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="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Nothing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Nothing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setComponent&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;ReactLifecycleHooksOptimization&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Nothing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&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;clear&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;setComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;component&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Mount&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;Unmount&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&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;clear&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Update&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app&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;Live demo is available on &lt;a href="https://codepen.io/Bunlong/pen/zYYXpZK"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Note
&lt;/h2&gt;

&lt;p&gt;According to the React docs, &lt;code&gt;getSnapshotBeforeUpdate&lt;/code&gt;, &lt;code&gt;componentDidCatch&lt;/code&gt; and &lt;code&gt;getDerivedStateFromError&lt;/code&gt;, there are no Hook equivalents for these methods yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/hooks-intro.html"&gt;Hooks at a Glance — React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading ❤ Say Hello! &lt;a href="https://github.com/bunlong"&gt;Github&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/bunlongvan"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/bunlongvan"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Component Lifecycle Methods Cheatsheet</title>
      <dc:creator>Bunlong</dc:creator>
      <pubDate>Sun, 02 Feb 2020 13:23:03 +0000</pubDate>
      <link>https://dev.to/bunlong/react-component-lifecycle-methods-cheatsheet-23gi</link>
      <guid>https://dev.to/bunlong/react-component-lifecycle-methods-cheatsheet-23gi</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HiDZKzEO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1000/1%2A2ANppcgcNvccNSsS8fHbnQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HiDZKzEO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1000/1%2A2ANppcgcNvccNSsS8fHbnQ.png" alt="React Component Lifecycle Methods Cheatsheet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://dev.to/bunlong/react-component-lifecycle-methods-cheatsheet-23gi"&gt;React Component Lifecycle Methods Cheatsheet&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://dev.to/bunlong/react-component-lifecycle-hooks-cheatsheet-41c3"&gt;React Component Lifecycle Hooks Cheatsheet&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each component in React has a lifecycle which you can monitor and manipulate.&lt;/p&gt;

&lt;p&gt;Lifecycle Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mounting:&lt;/strong&gt; Called before your component is displayed on the UI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Updating:&lt;/strong&gt; Caused by a change to props or state and rerendered the UI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unmounting:&lt;/strong&gt; Called when your UI will no longer display the component.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Mounting
&lt;/h2&gt;

&lt;h3&gt;
  
  
  constructor
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Mount immediately before render.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Initialize state.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Commonly Used Lifecycle Methods&lt;/span&gt;
&lt;span class="kd"&gt;constructor&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;h3&gt;
  
  
  componentDidMount
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Mount immediately after render.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Initialize state that requires DOM nodes, Network requests and side effects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;componentDidMount&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;h2&gt;
  
  
  Updating
&lt;/h2&gt;

&lt;h3&gt;
  
  
  shouldComponentUpdate
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Update immediately before render.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Allows developer to prevent rendering.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="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="c1"&gt;// Optional Parameters&lt;/span&gt;

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



&lt;h3&gt;
  
  
  render
&lt;/h3&gt;

&lt;p&gt;Code to display the component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Required&lt;/span&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  getSnapshotBeforeUpdate
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Update immediately before render output is committed to DOM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Capture DOM information such as scroll position which could change.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="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;// Optional Parameters&lt;/span&gt;

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



&lt;h3&gt;
  
  
  componentDidUpdate
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Update immediately after render.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Operate on updated DOM or handle network requests.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="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="c1"&gt;// Optional Parameters&lt;/span&gt;

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



&lt;h2&gt;
  
  
  Mounting &amp;amp; Updating
&lt;/h2&gt;

&lt;h3&gt;
  
  
  getDerivedStateFromProps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Mount and update immediately before render.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; When your state depends on props (should be avoided).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Rarely Used Lifecycle Methods&lt;/span&gt;
&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;getDerivedStateFromProps&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;// Optional Parameters&lt;/span&gt;

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



&lt;h2&gt;
  
  
  Unmounting
&lt;/h2&gt;

&lt;h3&gt;
  
  
  componentWillUnmount
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle:&lt;/strong&gt; Unmount.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose:&lt;/strong&gt; Clean up things such as event handlers, cancel network request, etc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;componentWillUnmount&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;h2&gt;
  
  
  Other Methods
&lt;/h2&gt;

&lt;h3&gt;
  
  
  componentDidCatch
&lt;/h3&gt;

&lt;p&gt;Creates an error boundary to captures errors from child components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Special Use Cases&lt;/span&gt;
&lt;span class="nx"&gt;componentDidCatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// Optional Parameters&lt;/span&gt;

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



&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://reactjs.org"&gt;React.Component - React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading ❤ Say Hello! &lt;a href="https://github.com/bunlong"&gt;Github&lt;/a&gt; | &lt;a href="https://www.linkedin.com/in/bunlongvan"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/bunlongvan"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
