<?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>Forem: Ankur Vyas</title>
    <description>The latest articles on Forem by Ankur Vyas (@ankurvyas).</description>
    <link>https://forem.com/ankurvyas</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%2F96990%2F003b362b-6202-4b69-8472-84e6dd16d7ee.jpg</url>
      <title>Forem: Ankur Vyas</title>
      <link>https://forem.com/ankurvyas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ankurvyas"/>
    <language>en</language>
    <item>
      <title>Rails 6 jQuery upgrade with webpacker!</title>
      <dc:creator>Ankur Vyas</dc:creator>
      <pubDate>Mon, 30 Mar 2020 07:16:01 +0000</pubDate>
      <link>https://forem.com/botreetechnologies/rails-6-upgrade-and-using-jquery-with-webpacker-3bib</link>
      <guid>https://forem.com/botreetechnologies/rails-6-upgrade-and-using-jquery-with-webpacker-3bib</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.botreetechnologies.com%2Fblog%2Fwp-content%2Fuploads%2F2020%2F03%2Frails-6-jquery-upgrade.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.botreetechnologies.com%2Fblog%2Fwp-content%2Fuploads%2F2020%2F03%2Frails-6-jquery-upgrade.png" alt="Rails Webpacker jQuery" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Adding jQuery to Rails 6 with webpacker will enable you to write ES 6 flavored JavaScript applications in no time. An essential thing to note is that Rails 6 comes installed with webpacker by default so you don't need to install it separately. In this article, I have outlined the process of adding jQuery with webpacker to your&lt;a href="https://www.botreetechnologies.com/blog/ruby-on-rails-development-obstacles-opportunities" rel="noopener noreferrer"&gt;Ruby on Rails Development&lt;/a&gt; version for building your frontend of the application.&lt;/p&gt;

&lt;p&gt;This blog is divided into three sections:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;jQuery in an older version of Rails&lt;/li&gt;
&lt;li&gt;Webpacker Installation&lt;/li&gt;
&lt;li&gt;Add jQuery with webpacker&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. JQuery in an older version of Rails:
&lt;/h3&gt;

&lt;p&gt;If you are using an older version on Rails and added &lt;a href="https://jquery.com/" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt; to it. Then the easiest way to add jQuery was to use &lt;a href="https://github.com/rails/jquery-rails" rel="noopener noreferrer"&gt;jquery-rails&lt;/a&gt; gem.&lt;/p&gt;

&lt;p&gt;By doing so the &lt;code&gt;jquery&lt;/code&gt; and &lt;code&gt;jquery-ujs&lt;/code&gt; files will be added to the asset pipeline and available for you to use. If they're not already in &lt;code&gt;app/assets/javascripts/application.js&lt;/code&gt; by default, add these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//= require jquery
//= require jquery_ujs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you are running Rails 5.1 and up, and if you have included &lt;code&gt;//= require rails-ujs&lt;/code&gt;, then &lt;code&gt;jquery_ujs&lt;/code&gt; is not needed anymore. You can just add:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//= require jquery
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Adding jQuery in this way makes it part of the &lt;a href="https://guides.rubyonrails.org/asset_pipeline.html" rel="noopener noreferrer"&gt;rails asset pipeline&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now if you are upgrading your rails version to Rails 6 and use it with &lt;a href="https://github.com/rails/webpacker" rel="noopener noreferrer"&gt;webpacker&lt;/a&gt; then you need to remove &lt;code&gt;jquery-rails&lt;/code&gt; from &lt;code&gt;Gemfile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Remove below from application.js&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//= require jquery
//= require jquery_ujs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Webpacker Installation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/rails/webpacker" rel="noopener noreferrer"&gt;Webpacker&lt;/a&gt; gem uses &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt; to manage app-like JavaScript modules in Rails. &lt;/p&gt;

&lt;p&gt;Webpacker makes it easy to use the JavaScript pre-processor and bundler &lt;code&gt;webpack 4.x.x+&lt;/code&gt; to manage application-like &lt;a href="https://www.botreetechnologies.com/blog/introducing-jquery-in-rails-6-using-webpacker" rel="noopener noreferrer"&gt;JavaScript in Rails 6 jquery&lt;/a&gt;. It coexists with the asset pipeline, as the primary purpose for webpack is app-like JavaScript, not images, CSS, or even JavaScript Sprinkles (that all continue to live in app/assets).&lt;/p&gt;

&lt;p&gt;Rails 6 comes with webpacker by default so you don’t need to do anything for it! When you create a brand new jquery Rails 6 app it will add webpacker and will do the configurations for you.&lt;/p&gt;
&lt;h3&gt;
  
  
  Read Also: &lt;a href="https://www.botreetechnologies.com/blog/notable-activerecord-changes-in-rails-6-part-1" rel="noopener noreferrer"&gt;Notable ActiveRecord changes in Rails 6 – Part1&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If you are upgrading rails app from an older version then you need to add below line manually in your &lt;code&gt;Gemfile&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'webpacker', '~&amp;gt; 4.x'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once you have added it then you need to run the following command to install Webpacker:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bundle exec rails webpacker:install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Optional: To fix &lt;a href="https://github.com/rails/webpacker/issues/1078" rel="noopener noreferrer"&gt;"unmet peer dependency"&lt;/a&gt; warnings,&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once installed, you can start writing modern ES6-flavored JavaScript apps right away:&lt;/p&gt;

&lt;p&gt;Rails will provide you with the basic directory structure as follows&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/javascript:
  ├── packs:
  │   # only webpack entry files here
  │   └── application.js
  └── src:
  │   └── application.css
  └── images:
      └── logo.svg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In &lt;code&gt;/packs/application.js&lt;/code&gt;, include this at the top of the file:&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;core-js/stable&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;regenerator-runtime/runtime&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can then link the JavaScript pack in Rails views using the &lt;a href="https://www.rubydoc.info/github/rails/webpacker/Webpacker%2FHelper:javascript_pack_tag" rel="noopener noreferrer"&gt;javascript_pack_tag&lt;/a&gt; helper.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;javascript_pack_tag&lt;/span&gt; &lt;span class="s1"&gt;'application'&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So by doing this, your &lt;a href="https://www.botreetechnologies.com/ruby-on-rails-development" rel="noopener noreferrer"&gt;Rails webpacker jquery&lt;/a&gt; installation will get completed. No need to do the above steps if you already are using Rails 6.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Add jQuery with webpacker
&lt;/h3&gt;

&lt;p&gt;In our Rails application run below command to add jQuery.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn add jquery
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will add jquery to Rails 6 to your application frontend. So we can access it in the webpacker. Just add following at &lt;code&gt;config/webpack/environment.js&lt;/code&gt;&lt;/p&gt;


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



&lt;p&gt;Add &lt;code&gt;require("jquery")&lt;/code&gt; to your &lt;code&gt;app/javascript/packs/application.js&lt;/code&gt;&lt;/p&gt;


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


&lt;p&gt;Now you will be able to add &lt;a href="https://www.botreetechnologies.com/blog/rails-6-notable-changes-in-railties-module" rel="noopener noreferrer"&gt;JQuery in Rails 6 application&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>webpacker</category>
      <category>jquery</category>
      <category>ruby</category>
    </item>
    <item>
      <title>How to put a Ruby on Rails application in Maintenance Mode</title>
      <dc:creator>Ankur Vyas</dc:creator>
      <pubDate>Mon, 19 Aug 2019 07:15:31 +0000</pubDate>
      <link>https://forem.com/botreetechnologies/how-to-put-a-ruby-on-rails-application-in-maintenance-mode-2k3b</link>
      <guid>https://forem.com/botreetechnologies/how-to-put-a-ruby-on-rails-application-in-maintenance-mode-2k3b</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.botreetechnologies.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F08%2Fruby-on-rails-application-in-maintenance-mode.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.botreetechnologies.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F08%2Fruby-on-rails-application-in-maintenance-mode.png" alt="How to put a Ruby on Rails application in Maintenance Mode" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the maintenance mode?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Maintenance mode&lt;/strong&gt; page is the user-friendly message for your site visitors indicating that we are working on something for which the site needs to be down for some time. We require this because we don't want our website to be broken for a specific amount of time while the site maintenance is in progress.&lt;/p&gt;

&lt;p&gt;When you &lt;a href="https://www.botreetechnologies.com/hire-ruby-on-rails-developers" rel="noopener noreferrer"&gt;hire Ruby on Rails programmers&lt;/a&gt;, they can take care of the entire maintenance mode page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why you require the maintenance mode page?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Performing upgrades (migrate rails version from one to another)&lt;/li&gt;
&lt;li&gt;Performing data migrations in the backend&lt;/li&gt;
&lt;li&gt;Migrating images or files from Amazon S3 to Google Cloud or vice versa&lt;/li&gt;
&lt;li&gt;And many more...&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to so do for Ruby on Rails applications?
&lt;/h3&gt;

&lt;p&gt;The easiest way to do is by using &lt;a href="https://github.com/biola/turnout" rel="noopener noreferrer"&gt;Turnout&lt;/a&gt; gem. Turnout is &lt;a href="http://rack.rubyforge.org/" rel="noopener noreferrer"&gt;Rack&lt;/a&gt; middleware with a &lt;a href="https://www.botreetechnologies.com/blog/ruby-on-rails-development-obstacles-opportunities" rel="noopener noreferrer"&gt;Ruby on Rails Development&lt;/a&gt; engine that allows you to put your app in maintenance mode easily.&lt;/p&gt;

&lt;p&gt;Turnout gem has the following features. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy installation&lt;/li&gt;
&lt;li&gt;Rake commands to turn maintenance mode on and off&lt;/li&gt;
&lt;li&gt;Easily provide a reason for each downtime without editing the maintenance.html file&lt;/li&gt;
&lt;li&gt;Allow certain IPs or IP ranges to bypass the maintenance page&lt;/li&gt;
&lt;li&gt;Allow certain paths to be accessible during maintenance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find them all of them &lt;a href="https://github.com/biola/turnout#features" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;Just add the following gem to your &lt;a href="https://www.botreetechnologies.com/blog/pagy-a-new-pagination-gem-in-the-realm-of-rails-world" rel="noopener noreferrer"&gt;Gemfile&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem 'turnout'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and do &lt;code&gt;bundle install&lt;/code&gt; that's it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Activation
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;$ rake maintenance: start.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Tada! It's done. When you do so, you will get the following page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgr8gdtblqp27fmqdaxsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgr8gdtblqp27fmqdaxsd.png" alt="Alt Maintenance mode" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ rake maintenance: start reason= "This is the custom reason!"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3oecpu6ery38m648rlob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3oecpu6ery38m648rlob.png" alt="Alt Custom reason" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find all the commands &lt;a href="https://github.com/biola/turnout#activation" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deactivation
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;$ rake maintenance: end.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/biola/turnout/blob/master/public/" rel="noopener noreferrer"&gt;Default maintenance pages&lt;/a&gt; are provided, but you can create your own &lt;code&gt;public/maintenance.[html|json|html.erb]&lt;/code&gt; files instead. Reach out to learn more about the &lt;a href="https://www.botreetechnologies.com/usa/web-development-company-new-york" rel="noopener noreferrer"&gt;expert web developers in NYC&lt;/a&gt; for the various ways to improve or build the quality of projects and across your company.&lt;/p&gt;

&lt;p&gt;A &lt;a href="https://www.botreetechnologies.com/ruby-on-rails-development" rel="noopener noreferrer"&gt;Ruby on Rails web development company&lt;/a&gt; will ensure that you activate and deactivate maintenance page at the right time.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Read Also: &lt;a href="http://www.rorexpertsindia.com/blog/top-3-tips-boost-performance-ruby-rails-application/" rel="noopener noreferrer"&gt;Top 3 tips to Boost Performance of your Ruby on Rails Application&lt;/a&gt;
&lt;/h3&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>maintenance</category>
      <category>gem</category>
    </item>
    <item>
      <title>How can we debounce render a React Component? (with example)</title>
      <dc:creator>Ankur Vyas</dc:creator>
      <pubDate>Thu, 25 Jul 2019 13:27:43 +0000</pubDate>
      <link>https://forem.com/botreetechnologies/how-can-we-debounce-render-a-react-component-with-example-33gj</link>
      <guid>https://forem.com/botreetechnologies/how-can-we-debounce-render-a-react-component-with-example-33gj</guid>
      <description>&lt;h2&gt;
  
  
  What is debouncing?
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://www.geeksforgeeks.org/debouncing-in-javascript/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/debouncing-in-javascript/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debouncing&lt;/strong&gt; in JavaScript is a practice used to improve browser performance. There might be some functionality in a web page which requires &lt;strong&gt;time-consuming computations&lt;/strong&gt;. If such a method is invoked frequently, it might greatly affect the performance of the browser, as JavaScript is a single-threaded language. Debouncing is a programming practice used to ensure that time-consuming tasks do not fire so often, that it stalls the performance of the web page. In other words, it &lt;strong&gt;limits the rate&lt;/strong&gt; at which a function gets invoked!&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%2Fwww.botreetechnologies.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F07%2Finteresting.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%2Fwww.botreetechnologies.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F07%2Finteresting.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, It sounds interesting!!! Next question is how we can use this in &lt;a href="https://www.botreetechnologies.com/blog/the-rising-popularity-of-reactjs-in-the-it-industry" rel="noopener noreferrer"&gt;React JS&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;The answer is &lt;a href="https://github.com/podefr/react-debounce-render" rel="noopener noreferrer"&gt;react-debounce-render&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;react-debounce-render&lt;/code&gt; is a &lt;strong&gt;Higher Order Component&lt;/strong&gt; that wraps your react components and debounces their rendering.&lt;/p&gt;

&lt;p&gt;This method can be used to prevent extra renders when a react component rapidly receives new props by delaying the triggering of the render until updates become less frequent. Doing so will improve the overall rendering time of the application, thus improving the user experience. It uses lodash debounce under the hood. Reach out to learn more about the &lt;a href="https://www.botreetechnologies.com/usa/web-development-company-new-york" rel="noopener noreferrer"&gt;web development NYC experts&lt;/a&gt; for the various ways to improve or build the quality of projects and across your company.&lt;/p&gt;

&lt;h3&gt;
  
  
  Read Also: &lt;a href="https://www.botreetechnologies.com/blog/top-libraries-to-use-with-advanced-react-js-applications" rel="noopener noreferrer"&gt;Top Libraries to use with Advanced React JS Applications!&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You can find my whole source code at &lt;a href="https://github.com/AnkurVyas-BTC/react-debounce-example" rel="noopener noreferrer"&gt;https://github.com/AnkurVyas-BTC/react-debounce-example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see how we can use react-debounce-render with our big &lt;a href="https://www.botreetechnologies.com/react-native-development" rel="noopener noreferrer"&gt;React applications&lt;/a&gt;!&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%2Ffph18i2q6yd95rmbleye.gif" 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%2Ffph18i2q6yd95rmbleye.gif" alt="react debounce example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Only two things are present here -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Simple Textbox&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. Displaying data based on the input text&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my sample application, what I have done is to print the input text after 2 seconds. You can consider it a heavy time-consuming computation.&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;Component&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;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;sleep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milliseconds&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;var&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&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;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;start&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;milliseconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;break&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;timedOutDisplay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputVal&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Heavy calculation based on input =&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;inputVal&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&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="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Fragment&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timedOutDisplay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&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;inputVal&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;/React.Fragment&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="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Calculator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code &lt;code&gt;this.sleep(2000)&lt;/code&gt; allows adding 2 seconds delay.&lt;/p&gt;

&lt;p&gt;The examples are as follows - &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Without Debounce Rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you type any text (&lt;code&gt;12345&lt;/code&gt; in the GIF), the input becomes unusable and is blocking UI.&lt;/p&gt;

&lt;p&gt;It will take every change from 1 to 2, 2 to 3, 3 to 4 and 4 to 5. So you will see - &lt;/p&gt;

&lt;p&gt;Heavy calculation based on input =&amp;gt; 12345&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;after ~10 seconds ( 2 seconds delay after each input)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. With Debounce Rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can make any component debounce rendered by adding two lines.&lt;/p&gt;

&lt;p&gt;Import debounceRender and wrap component within debounceRender&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;debounceRender&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-debounce-render&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;debounceRender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WithDebounceCalculator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at below example&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;Component&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;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;debounceRender&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-debounce-render&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WithDebounceCalculator&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nx"&gt;sleep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milliseconds&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;var&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&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;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;start&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;milliseconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;break&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;timedOutDisplay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputVal&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Heavy calculation based on input =&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;inputVal&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&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="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Fragment&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timedOutDisplay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&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;inputVal&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;/React.Fragment&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="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;debounceRender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;WithDebounceCalculator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you type any text (&lt;code&gt;12345&lt;/code&gt; in the GIF) the input is very smooth and is not blocking UI.&lt;br&gt;
If will take change 12345 as a collection. So you will see -&lt;/p&gt;

&lt;p&gt;Heavy calculation based on input =&amp;gt; 12345&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;after ~2 seconds&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you are using filters which requires heavy computation the debounced rendering is an appropriate fit!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>debouncing</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
