<?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: Cronj IT Technologies</title>
    <description>The latest articles on DEV Community by Cronj IT Technologies (@sasicronj).</description>
    <link>https://dev.to/sasicronj</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F609391%2Fee7b5940-9437-4dc0-902d-1d8d54399916.png</url>
      <title>DEV Community: Cronj IT Technologies</title>
      <link>https://dev.to/sasicronj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sasicronj"/>
    <language>en</language>
    <item>
      <title>Javascript String Methods | Properties | Objects</title>
      <dc:creator>Cronj IT Technologies</dc:creator>
      <pubDate>Tue, 20 Apr 2021 02:42:09 +0000</pubDate>
      <link>https://dev.to/sasicronj/javascript-string-methods-properties-objects-550a</link>
      <guid>https://dev.to/sasicronj/javascript-string-methods-properties-objects-550a</guid>
      <description>&lt;p&gt;A javascript string is data type in any programming language and it’s used to store text rather than numbers. In Javascript, strings are used for manipulating the text. A string can be declared with enclosing of single quotes or double quotes or backticks like below examples.&lt;/p&gt;

&lt;p&gt;var singleQuote = 'single-quote';&lt;/p&gt;

&lt;p&gt;var doubleQuote = "double-quote";&lt;/p&gt;

&lt;p&gt;var backTicks = &lt;code&gt;back-ticks&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;You can use quotes inside the string, as long as they didn’t match with surrounding quotes.&lt;/p&gt;

&lt;p&gt;var person = "It's me..";&lt;/p&gt;

&lt;p&gt;var company = 'This is called "Cronj" ';&lt;/p&gt;

&lt;p&gt;var company = "This is called 'Cronj’ ";&lt;/p&gt;

&lt;p&gt;Javascript Strings have to place within the quotes, otherwise, it will misunderstand:&lt;/p&gt;

&lt;p&gt;var country = "This is "India” country'';&lt;/p&gt;

&lt;p&gt;In the above example, the string will take up to “This is “. So, The solution here is to use backslash(). Backslash character converts special characters into the string character.&lt;/p&gt;

&lt;p&gt;Eg: Double Quote (\’)&lt;/p&gt;

&lt;p&gt;var country = "This is \"India\" country";&lt;/p&gt;

&lt;p&gt;Output: This is “India” country&lt;/p&gt;

&lt;p&gt;Eg: Single Quote (\”)&lt;/p&gt;

&lt;p&gt;var country = 'This is \'India\' country';&lt;/p&gt;

&lt;p&gt;Output: This is ‘India’ country&lt;/p&gt;

&lt;p&gt;Eg: Backslash ()&lt;/p&gt;

&lt;p&gt;var specialCharacter = "This character \ is called backslash";&lt;/p&gt;

&lt;p&gt;Output: This character \ is called backslash.&lt;/p&gt;

&lt;p&gt;Find String Length:&lt;/p&gt;

&lt;p&gt;In Javascript, we have a built-in property called length. By using length property we can find the length of a javascript string.&lt;/p&gt;

&lt;p&gt;var alphabates = "Cronj";&lt;/p&gt;

&lt;p&gt;var strLength  = alphabates.length;&lt;/p&gt;

&lt;p&gt;Long code lines break:&lt;/p&gt;

&lt;p&gt;Programmers are used to avoiding code lines above 80 characters. In Javascript best practice is to break line after an operator&lt;/p&gt;

&lt;p&gt;Eg: document.getElementById(“string”).innerHTML = “Hello world”;&lt;/p&gt;

&lt;p&gt;We can also break the code within the text also, like below by using the backslash.&lt;/p&gt;

&lt;p&gt;Eg: document.getElementById(“string”).innerHTML = “Hello \&lt;/p&gt;

&lt;p&gt;World”;&lt;/p&gt;

&lt;p&gt;Some browsers do not allow the spaces after . So safer way to break like using javascript string concatenation using the ‘+‘ operator.&lt;/p&gt;

&lt;p&gt;Eg: document.getElementById(“string”).innerHTML = “Hello” +&lt;/p&gt;

&lt;p&gt;“World”;&lt;/p&gt;

&lt;p&gt;Sting Objects:&lt;/p&gt;

&lt;p&gt;In Javascript, String can be objects. Here strings are also be defined as objects with the keyword new:&lt;/p&gt;

&lt;p&gt;var personNameString = "John";&lt;/p&gt;

&lt;p&gt;var personNameObject = new String("John");&lt;/p&gt;

&lt;p&gt;Here typeof(personNameString) will return string and typeof(personNameObject) will return object. But the better way to define string without new, because it will affect execution speed and it causes unexpected results.&lt;/p&gt;

&lt;p&gt;String properties:&lt;/p&gt;

&lt;p&gt;Constructor returns the string’s constructor function. Length returns the length of a javascript string. Prototype allows you to add methods and properties to an object.&lt;/p&gt;

&lt;p&gt;String Methods:&lt;/p&gt;

&lt;p&gt;charAt():&lt;br&gt;
charAt() method will returns the character at the specified position(index).&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var exString = "Hello world";&lt;/p&gt;

&lt;p&gt;var response = exString.charAt(6);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: w&lt;/p&gt;

&lt;p&gt;charCodeAt():&lt;br&gt;
charCodeAt() method will return the Unicode of the character at the specified index in a javascript string.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var exString = "Hello world";&lt;/p&gt;

&lt;p&gt;var response = exString.charAt(6);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: 72&lt;/p&gt;

&lt;p&gt;concat():&lt;br&gt;
concat() method is used to join strings. This method doesn’t change the existing string, It will return the new concatenated string as output.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string1 = "Hello";&lt;/p&gt;

&lt;p&gt;var string2 = "world";&lt;/p&gt;

&lt;p&gt;var response = string1.concat(string2);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Helloworld&lt;/p&gt;

&lt;p&gt;You can concatenate two or more javascript strings.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string1 = "Hello";&lt;/p&gt;

&lt;p&gt;var string2 = " world";&lt;/p&gt;

&lt;p&gt;var string3 = " Have a nice day!!";&lt;/p&gt;

&lt;p&gt;var response = string1.concat(string2, string3); console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Hello world Have a nice day!!&lt;/p&gt;

&lt;p&gt;[Read: Node Js: Non-blocking or asynchronous | Blocking or synchronous]&lt;/p&gt;

&lt;p&gt;endsWith():&lt;br&gt;
endsWith() method determines whether a javascript string ends with specified string or not. This method will return true if a string exists or it will return false if the string does not exist.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string1 = "Hello world, Have a nice day!";&lt;/p&gt;

&lt;p&gt;var a = string1.endsWith("day!");&lt;/p&gt;

&lt;p&gt;console.log(a);&lt;/p&gt;

&lt;p&gt;Output: true&lt;/p&gt;

&lt;p&gt;fromCharCode():&lt;br&gt;
fromCharCode() method converts the unicode character.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string1 = String.fromCharCode(67);&lt;/p&gt;

&lt;p&gt;console.log(string1);&lt;/p&gt;

&lt;p&gt;Output: C&lt;/p&gt;

&lt;p&gt;includes():&lt;br&gt;
includes() method determines whether a string contains in the characters of the specified javascript string, and returns true if the string contains the characters and false if not contains.&lt;/p&gt;

&lt;p&gt;var string1 = "Hello world, Have a nice day!";&lt;/p&gt;

&lt;p&gt;var a = string1.includes("Have");&lt;/p&gt;

&lt;p&gt;Output: true&lt;/p&gt;

&lt;p&gt;indexOf():&lt;br&gt;
indexOf() method determines the first occurrence of a specified value in a javascript string and it returns -1 if the value is not found in our occurrence.&lt;/p&gt;

&lt;p&gt;var string1 = "Hello world, Have a nice day!";&lt;/p&gt;

&lt;p&gt;var a = string1.indexOf("Good");&lt;/p&gt;

&lt;p&gt;Output: -1&lt;/p&gt;

&lt;p&gt;lastIndexOf():&lt;br&gt;
lastIndexOf() method returns the position of the last occurrence of a specified value in a javascript string and it returns -1 if the value is not found in our occurrence.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string1 = "Hello world, Have a nice day!";&lt;/p&gt;

&lt;p&gt;var a = string1.lastIndexOf(" day!");&lt;/p&gt;

&lt;p&gt;Output: 24&lt;/p&gt;

&lt;p&gt;match():&lt;br&gt;
match() method will search a string for a match against a regular expression and returns the matches as an array.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "The rain in India stays mainly in the plain";&lt;/p&gt;

&lt;p&gt;var response = string.match(/ain/g);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: ain,ain,ain&lt;/p&gt;

&lt;p&gt;repeat():&lt;br&gt;
repeat() method always returns a new string with a specified number of copies of the string.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season! ";&lt;/p&gt;

&lt;p&gt;var response = string.repeat(2);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter season! Winter season!&lt;/p&gt;

&lt;p&gt;replace():&lt;br&gt;
replace() will search a javascript string for a specified value or a regular expression and returns a new string where the specified values are replaced.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.replace("!", "@");&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter season@&lt;/p&gt;

&lt;p&gt;search():&lt;br&gt;
search() method searches a javascript string for a specified value or a regular expression and returns the position of the match.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.search("season");&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: 7&lt;/p&gt;

&lt;p&gt;slice():&lt;br&gt;
slice() method to extract a part of the javascript string and it returns a new string. It takes two parameters like start and endpoints that what we want to extract.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.slice(0, 6);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter&lt;/p&gt;

&lt;p&gt;split():&lt;br&gt;
split() method is used to split a javascript string into an array of substrings and it returns a new array&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.split(" ");&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter, season!&lt;/p&gt;

&lt;p&gt;[Read: Node JS WebSocket: Examples | Chat Features | Client-Server communication]&lt;/p&gt;

&lt;p&gt;substr():&lt;br&gt;
substr() method always extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.substr(0, 8);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter s&lt;/p&gt;

&lt;p&gt;substring():&lt;br&gt;
substring() method will extract the characters from the two specified positions in parameters and returns the new substring. Two parameters are starting position and ending positions.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.substring(0, 8);&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter s&lt;/p&gt;

&lt;p&gt;toString():&lt;br&gt;
toString() method returns the value of a string. If the value in the variable is object then it will convert as a string object.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "Winter season!";&lt;/p&gt;

&lt;p&gt;var response = string.toString();&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter season!&lt;/p&gt;

&lt;p&gt;trim():&lt;br&gt;
trim() method removes the white spaces of a sting in both(starting and ending) sides.&lt;/p&gt;

&lt;p&gt;Eg:&lt;/p&gt;

&lt;p&gt;var string = "    Winter season! ";&lt;/p&gt;

&lt;p&gt;var response = string.trim();&lt;/p&gt;

&lt;p&gt;console.log(response);&lt;/p&gt;

&lt;p&gt;Output: Winter season!&lt;/p&gt;

&lt;p&gt;If you’ve any doubts, please let us know through comment!!&lt;/p&gt;

&lt;p&gt;Follow Us on Facebook | Twitter | LinkedIn.&lt;/p&gt;

&lt;p&gt;Be it a software developer, programmer, coder, or a consultant, CronJ has it all. CronJ has been a trustworthy company for startups, small companies, and large enterprises. Hire the web of experienced &lt;a href="https://www.cronj.com/reactjs-development-company.html" rel="nofollow"&gt;ReactJS Development Services&lt;/a&gt; for your esteemed project today.&lt;/p&gt;

&lt;p&gt;Let CronJ assist you..!&lt;/p&gt;

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

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Memory Management in Javascript | Memory life cycle</title>
      <dc:creator>Cronj IT Technologies</dc:creator>
      <pubDate>Fri, 16 Apr 2021 04:33:32 +0000</pubDate>
      <link>https://dev.to/sasicronj/memory-management-in-javascript-memory-life-cycle-19bb</link>
      <guid>https://dev.to/sasicronj/memory-management-in-javascript-memory-life-cycle-19bb</guid>
      <description>&lt;p&gt;Memory Management! When things (string, array, object) are created, memory is allocated to them in JavaScript. Unlike Low-Level Programming Language C, JavaScript does not have alloc(), malloc(), free() primitive to do a job for them. Memory is automatically freed when that is no longer useful. &lt;/p&gt;

&lt;p&gt;This process is called Garbage Collection. Word Automatically brings confusion to developers, that they need not worry about Memory, And this is a mistake, Sir! &lt;/p&gt;

&lt;p&gt;In memory management, its life cycle&lt;br&gt;
Allocate Memory(explicit or implicit depending on a programming language for us it is implicit)&lt;br&gt;
Use it.&lt;br&gt;
Release it.&lt;br&gt;
This is a general life cycle.&lt;/p&gt;

&lt;p&gt;Allocation Of Memory in  JavaScript for memory management&lt;br&gt;
When values are assigned to any variable memory is assigned to it.&lt;/p&gt;

&lt;p&gt;var a = 10;&lt;/p&gt;

&lt;p&gt;var b = "CronJ";&lt;/p&gt;

&lt;p&gt;var c = {&lt;/p&gt;

&lt;p&gt;d : 1,&lt;br&gt;
   e: 'name'&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;var f = [1,2,3,4,5]&lt;/p&gt;

&lt;p&gt;var g = new Date();&lt;/p&gt;

&lt;p&gt;Release when the memory is not needed anymore&lt;br&gt;
This is the climax scene. When? how? to decide memory is no longer useful. High-Level Programming Language like Javascript has some software called Garbage Collector, which does the job of automatic memory deallocation. This is the approximation Process. Exact point from memory management which that memory is not gone any benefits to an application is not solved yet.&lt;/p&gt;

&lt;p&gt;Garbage Collector&lt;br&gt;
Finding the exact point from which memory will be no longer useful is not solved yet. This is the general problem any Programming language face.&lt;/p&gt;

&lt;p&gt;Reference-counting garbage collection:&lt;br&gt;
Any variable which has zero reference points can be considered to garbage.&lt;/p&gt;

&lt;p&gt;Let’s take an example. Taken Mozilla developer Guide.&lt;/p&gt;

&lt;p&gt;var o = { &lt;br&gt;
  a: {&lt;br&gt;
    b: 2&lt;br&gt;
  }&lt;br&gt;
}; &lt;br&gt;
// 2 objects are created. One is referenced by the other as one of its properties.&lt;br&gt;
// The other is referenced by virtue of being assigned to the 'o' variable.&lt;br&gt;
// Obviously, none can be garbage-collected&lt;/p&gt;

&lt;p&gt;var o2 = o; // the 'o2' variable is the second thing that &lt;br&gt;
            // has a reference to the object&lt;br&gt;
o = 1;      // now, the object that was originally in 'o' has a unique reference&lt;br&gt;
            // embodied by the 'o2' variable&lt;/p&gt;

&lt;p&gt;var oa = o2.a; // reference to 'a' property of the object.&lt;br&gt;
               // This object has now 2 references: one as a property, &lt;br&gt;
               // the other as the 'oa' variable&lt;/p&gt;

&lt;p&gt;o2 = 'yo'; // The object that was originally in 'o' has now zero&lt;br&gt;
           // references to it. It can be garbage-collected.&lt;br&gt;
           // However its 'a' property is still referenced by &lt;br&gt;
           // the 'oa' variable, so it cannot be freed&lt;/p&gt;

&lt;p&gt;oa = null; // The 'a' property of the object originally in o &lt;br&gt;
           // has zero references to it. It can be garbage collected.&lt;/p&gt;

&lt;p&gt;Limitation: cycles&lt;br&gt;
There are limitations to it. If two objects are referencing to each other then they will be thrown out of the scope of garbage collection.&lt;/p&gt;

&lt;p&gt;var a = {};&lt;/p&gt;

&lt;p&gt;var b = {};&lt;/p&gt;

&lt;p&gt;a.c = b;&lt;/p&gt;

&lt;p&gt;b.c = a;&lt;/p&gt;

&lt;p&gt;Conclusion: &lt;br&gt;
Although JavaScript has software called Garbage Collector. We have to take care that we are not causing circular referencing to variables. We are not coding anything which will lead to throwing variables from out of Garbage collection Cycle.&lt;br&gt;
Be it a software developer, programmer, coder, or a consultant, CronJ has it all. CronJ has been a trustworthy company for startups, small companies, and large enterprises. Hire the web of experienced &lt;a href="https://www.cronj.com/reactjs-development-company.html" rel="nofollow"&gt;ReactJS Development Services&lt;/a&gt; for your esteemed project today.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Redux Middleware: A Perfect Beginner’s Guide</title>
      <dc:creator>Cronj IT Technologies</dc:creator>
      <pubDate>Tue, 06 Apr 2021 10:36:27 +0000</pubDate>
      <link>https://dev.to/sasicronj/redux-middleware-a-perfect-beginner-s-guide-1ia7</link>
      <guid>https://dev.to/sasicronj/redux-middleware-a-perfect-beginner-s-guide-1ia7</guid>
      <description>&lt;p&gt;Redux Middleware: What struck your mind when you first heard the term ‘Middleware’? Let’s first try to understand it with the most general definition:-&lt;/p&gt;

&lt;p&gt;Middleware offers a means for communicating with the action being dispatched before they reach the reducer.&lt;/p&gt;

&lt;p&gt;Before understanding Redux Middleware, you should have a clear concept of redux. So let’s have a brief introduction about redux.&lt;/p&gt;

&lt;p&gt;Redux&lt;br&gt;
Redux is an open-source JavaScript library for front-end development. It’s an application data flow architecture. It is used with React to solve the ‘state transfer problem.’ It maintains a single immutable store tree to keep the state of the whole application which can’t be changed directly. A new object of the state is created when something changes (using actions and reducers). Redux has become popular because of its simplicity and small size(2 KB).&lt;/p&gt;

&lt;p&gt;Redux Middleware&lt;br&gt;
Redux middleware acts as a medium between dispatching an action and handing over the action to the reducer. It listens to all dispatches and executes code with the details of the actions and the current states. It is possible to combine multiple middlewares to add new features, and each middleware does not require an understanding of what happened before and after.&lt;/p&gt;

&lt;p&gt;Action   -&amp;gt; Middleware  -&amp;gt; Reducer &lt;/p&gt;

&lt;p&gt;Examples of middleware include, handle asynchronous requests(like HTTP call to the server), logging, routing, etc.&lt;/p&gt;

&lt;p&gt;Middlewares are mainly used to handle asynchronous actions in your application. Redux’s popular middleware libraries that allow for side effects and asynchronous actions are Redux-thunk and Redux-Saga.&lt;/p&gt;

&lt;p&gt;Redux thunk&lt;br&gt;
Redux thunk is the most popular middleware that allows you to call action creators, which then returns a function instead of an action object. This function receives the store’s dispatch method, which is then used to dispatch the regular synchronous actions within the function’s body once the asynchronous operations have been completed. It is a programming concept where the function(thunk) is used to delay the evaluation of the operation or process. It is used for communicating asynchronously with an external API(Application Programming Interface) to fetch or save data.&lt;/p&gt;

&lt;p&gt;Let’s see how you can include Redux-thunk in your application.&lt;/p&gt;

&lt;p&gt;Installation &amp;amp; Setup&lt;/p&gt;

&lt;p&gt;$ yarn add redux-thunk&lt;/p&gt;

&lt;p&gt;Or using npm:&lt;/p&gt;

&lt;p&gt;$ npm install redux-thunk&lt;/p&gt;

&lt;p&gt;Let’s try to understand how ‘thunk’ actually works by implementing a small example of fetching the details of a particular user by hitting an API.&lt;/p&gt;

&lt;p&gt;// Index.js&lt;/p&gt;

&lt;p&gt;import React from 'react';&lt;/p&gt;

&lt;p&gt;import ReactDOM from 'react-dom';&lt;/p&gt;

&lt;p&gt;import './index.css';&lt;/p&gt;

&lt;p&gt;import App from './App';&lt;/p&gt;

&lt;p&gt;import * as serviceWorker from './serviceWorker';&lt;/p&gt;

&lt;p&gt;import userDataReducer from './Reducer/reducer';&lt;/p&gt;

&lt;p&gt;import {Provider} from 'react-redux';&lt;/p&gt;

&lt;p&gt;import {createStore, applyMiddleware} from 'redux';&lt;/p&gt;

&lt;p&gt;import thunk from 'redux-thunk';&lt;/p&gt;

&lt;p&gt;const store= createStore(userDataReducer, applyMiddleware(thunk))&lt;/p&gt;

&lt;p&gt;ReactDOM.render(, document.getElementById('root'));&lt;/p&gt;

&lt;p&gt;serviceWorker.unregister();&lt;/p&gt;

&lt;p&gt;// Api&lt;/p&gt;

&lt;p&gt;Here you can hit the API and return the response back to the calling function.&lt;/p&gt;

&lt;p&gt;import axios from 'axios';&lt;/p&gt;

&lt;p&gt;const reposApi = {&lt;/p&gt;

&lt;p&gt;getUserDetails: () =&amp;gt; {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let url = 'https://users/getUserData/1';

   return axios.get(url);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;export default reposApi;&lt;/p&gt;

&lt;p&gt;// Action creator&lt;/p&gt;

&lt;p&gt;It returns a function that calls an API, which further returns a promise. Once it has been resolved, it dispatches an action again, which is then matched to the corresponding action-type and eventually reaches the reducer.&lt;/p&gt;

&lt;p&gt;import * as actionType from './actionType';&lt;/p&gt;

&lt;p&gt;import reposApi from '../Api/repos';&lt;/p&gt;

&lt;p&gt;export function getUserDetails(){&lt;/p&gt;

&lt;p&gt;return (dispatch) =&amp;gt; {&lt;/p&gt;

&lt;p&gt;reposApi.getUserDetails()&lt;/p&gt;

&lt;p&gt;.then(response =&amp;gt; {&lt;/p&gt;

&lt;p&gt;dispatch(getUserDetailsAction(response));&lt;/p&gt;

&lt;p&gt;})&lt;/p&gt;

&lt;p&gt;.catch(err =&amp;gt; {&lt;/p&gt;

&lt;p&gt;console.log("error occurred ====&amp;gt;&amp;gt;&amp;gt;", err);&lt;/p&gt;

&lt;p&gt;})&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;export const getUserDetailsAction = item =&amp;gt; {&lt;/p&gt;

&lt;p&gt;return {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   type: actionType.GET_PROFILE,

   payload: item
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// Reducer&lt;/p&gt;

&lt;p&gt;Reducer updates the state object after performing the required calculation.&lt;/p&gt;

&lt;p&gt;import * as actionType from "../Action/actionType";&lt;/p&gt;

&lt;p&gt;const initialState = {&lt;/p&gt;

&lt;p&gt;profile: {}&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;const userDataReducer = (state = initialState, action) =&amp;gt; {&lt;/p&gt;

&lt;p&gt;switch (action.type) {&lt;/p&gt;

&lt;p&gt;case actionType.GET_PROFILE:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; return {

   ...state,

   profile: action.payload.data

 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;default:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   return state;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;export default userDataReducer;&lt;/p&gt;

&lt;p&gt;Let’s move on to the next Redux middleware.&lt;/p&gt;

&lt;p&gt;Redux Saga&lt;br&gt;
Like Redux-Thunk, Redux-Saga is a middleware library used to handle side effects and asynchronous action calls in a redux app in an effective way. It achieves this by using the generator function. Generator functions are not like the actual functions which we know, but rather it is a special type of function which has the ability to pause in the middle of the execution and resume later. Not only this, but you can also do this as many times as you want. Inside the generator function, there is a keyword ‘yield’, which is used to pause the execution. It is favored over thunk, because of easy testability.&lt;/p&gt;

&lt;p&gt;Here is the syntax of a generator function:-&lt;/p&gt;

&lt;p&gt;function *function_name{&lt;/p&gt;

&lt;p&gt;yield “Hi, I am generator”;&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Let’s try to understand Redux-Saga by implementing a small example in which we will hit an API to fetch the user.&lt;/p&gt;

&lt;p&gt;// Action Creators&lt;/p&gt;

&lt;p&gt;const requestUser = () =&amp;gt; {&lt;/p&gt;

&lt;p&gt;return { type: 'REQUESTED_USER' }&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;const requestUserSuccess = (data) =&amp;gt; {&lt;/p&gt;

&lt;p&gt;return { type: 'REQUESTED_USER_SUCCESS', url: data.message }&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;const requestUserError = () =&amp;gt; {&lt;/p&gt;

&lt;p&gt;return { type: 'REQUESTED_USER_FAILURE' }&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;const fetchUser = () =&amp;gt; {&lt;/p&gt;

&lt;p&gt;return { type: 'FETCHED_USER' }&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;// Sagas&lt;/p&gt;

&lt;p&gt;function* watchFetchUser() {&lt;/p&gt;

&lt;p&gt;yield takeEvery('FETCHED_USER', fetchUserAsync);&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;function* fetchUserAsync() {&lt;/p&gt;

&lt;p&gt;try {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; yield put(requestUser());

 const data = yield call(() =&amp;gt; {

   return fetch('https://getData/userDetails/user')

           .then(res =&amp;gt; res.json())

   }

 );

 yield put(requestUserSuccess(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;} catch (error) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; yield put(requestUserError());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// Reducer&lt;/p&gt;

&lt;p&gt;const initialState = {&lt;/p&gt;

&lt;p&gt;url: '',&lt;/p&gt;

&lt;p&gt;error: false&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;const reducer = (state = initialState, action) =&amp;gt; {&lt;/p&gt;

&lt;p&gt;switch (action.type) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; case 'REQUESTED_USER':

   return {

     url: '',

     error: false

   };

 case 'REQUESTED_USER_SUCCESS':

   return {

     url: action.url,

     error: false

   };

 case 'REQUESTED_USER_FAILURE':

   return {

     url: '',

     error: true

   };

 default:

   return state;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;// Store&lt;/p&gt;

&lt;p&gt;const sagaMiddleware = createSagaMiddleware();&lt;/p&gt;

&lt;p&gt;const store = createStore(&lt;/p&gt;

&lt;p&gt;reducer,&lt;/p&gt;

&lt;p&gt;applyMiddleware(sagaMiddleware)&lt;/p&gt;

&lt;p&gt;);&lt;/p&gt;

&lt;p&gt;sagaMiddleware.run(watchFetchUser);&lt;/p&gt;

&lt;p&gt;Working&lt;br&gt;
The component first dispatches the action FETCHED_USER. Then, the watcher saga (watchFetchUser) takes the dispatched action and calls the worker saga (fetchUserAsync), followed by the execution of the API call. At last, an action to update the state is dispatched (success or failure).&lt;br&gt;
Be it a software developer, programmer, coder, or a consultant, CronJ has it all. CronJ has been a trustworthy company for startups, small companies, and large enterprises. Hire the web of experienced &lt;a href="https://www.cronj.com/reactjs-development-company.html" rel="nofollow"&gt;ReactJS Development Services&lt;/a&gt; for your esteemed project today.&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
