<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Divyanamdev on Medium]]></title>
        <description><![CDATA[Stories by Divyanamdev on Medium]]></description>
        <link>https://medium.com/@divyanamdev?source=rss-e5141317eba0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YkkUQaDMSOpdZMvfKfEXJQ.jpeg</url>
            <title>Stories by Divyanamdev on Medium</title>
            <link>https://medium.com/@divyanamdev?source=rss-e5141317eba0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:16:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divyanamdev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Look at React Hook “useReducer()”]]></title>
            <link>https://divyanamdev.medium.com/look-at-react-hook-usereducer-3f8f40f013f4?source=rss-e5141317eba0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f8f40f013f4</guid>
            <dc:creator><![CDATA[Divyanamdev]]></dc:creator>
            <pubDate>Wed, 20 Jul 2022 07:06:18 GMT</pubDate>
            <atom:updated>2022-07-20T07:06:18.295Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KbpcytjZcMmKeyW1OAAC2A.png" /></figure><blockquote>The word “reducer” might evoke images of Redux — but I promise you don’t have to understand Redux to read this blog, or to use the new useReducer hook that comes with the React V16.8.</blockquote><p>Managing state in react is one of the main issue you will be face while developing react application. <strong>useState </strong>is of course one of the most common way to manage and update state in functional react component.</p><blockquote>There is also a lots of libraries which offering opinionated ways to manage your entire state like <a href="https://redux.js.org/">https://redux.js.org</a>/ , Mobx, Recoil and Xstate.</blockquote><p>but before jumping to a library to help you manage your state you should be aware of another native way to manage your state:useReducer. in can be very powerful when used in a right way and for the right purpose.in fact its so powerful that the famous Redux library can be thought of as just a big optimized useReducer.</p><h3><strong>What is useReducer and How it works -</strong></h3><p>u<em>seReducer</em> is a React Hook that give us more control over state management than useState. making it easier to manage complex states , its basic structure is:</p><p>const [state, dispatch] = useReducer(reducer, initialState)</p><p>Combined with other React Hook such as useContext , it works almost similer to Redux. The difference is that Redux creates a global state container (a store) while useReducer creates an independent state container within our component.</p><p>React useReducer can be used to manage state that depends on previous state , and efficiently manage multiple complex states.</p><p>useReducer hook takes two arguments inside it first one is reducer function and second is initialState. then it returns an array of two items , the <strong>current state </strong>and <strong>dispatch function .</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtZdzfsWkb_4g5SXQITjxQ.png" /></figure><blockquote>Let’s see what is the meaning of these terms- initialState , Action object , dispatch and reducer function.</blockquote><h3>1. Initial State</h3><p>Initial state is the value the state initialised with .</p><p>Let’s see the example -</p><p>for increasing and decreasing the value of counter , the initial state would be -</p><p>const initialState = {</p><p>Counter:0</p><p>};</p><h3>2. Action Object-</h3><p>An action object is an object that describes how to update the state.</p><p>By convention , an action is just a JavaScript object which contains two properties -</p><ol><li><strong>type: </strong>a unique identifier for the type of state transformation you want to perform.</li><li><strong>payload (optional) : </strong>The value that should be used to update some part of the state.</li></ol><p>Here is what an action look like-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oygdRLUfirtC9_kXHS0doQ.png" /></figure><h3><strong>3. Dispatch Function :</strong></h3><p>The dispatch function is a special function that dispatches an action object.</p><p>The dispatch function is created for your by the useReducer() hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_oagbVdh6LiD2Lz5EnHygg.png" /></figure><p>when you want to update the state (usually from an event handler or after completing a fetch request) , you just call the dispatch function with the appropriate action object : dispatch(actionObject).</p><h3>4. Reducer Function:</h3><p>It is pure function that accept state and action as parameter and returns an updated state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*jeTjY6QIkmzYQHOiIoykLw.png" /></figure><h3>Conclusion :</h3><p>This article demonstrated how to handle complex states with useReducer, exploring its use cases and tradeoffs. It’s important to note that no single React hook can solve all our challenges, and knowing what each hook does can help us decide when to use it.</p><blockquote>I hope this article help you to understand when to use useReducer and resolved all your doubts ,</blockquote><blockquote>if you find this article useful , guys please like and share with your friends and stay connected for more technical blogs.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f8f40f013f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction To CSS Grid Property]]></title>
            <link>https://divyanamdev.medium.com/an-introduction-to-css-grid-property-404ebb22fe89?source=rss-e5141317eba0------2</link>
            <guid isPermaLink="false">https://medium.com/p/404ebb22fe89</guid>
            <dc:creator><![CDATA[Divyanamdev]]></dc:creator>
            <pubDate>Sun, 29 Aug 2021 05:18:39 GMT</pubDate>
            <atom:updated>2021-08-29T05:18:39.815Z</atom:updated>
            <content:encoded><![CDATA[<h4>CSS Grid Properties</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*TcC1xc0DkSwi6xTpUBRTqg.png" /></figure><h3>What is CSS Grid ?</h3><p>CSS Grid is a powerful tool that allows for two-dimensional layouts to be created on the web. This guide was created as a resource to help you better understand and learn Grid, and was organized in a way I thought made the most sense when learning it.</p><h3>Benefits of a CSS Grid</h3><p>Thanks to its flexibility, a CSS grid allows web designers to achieve almost any type of layout that they need. It’s great for dividing up the major regions of a page into smaller sections or setting the relationship between elements in terms of size and position.</p><p>While it aligns page elements by columns and rows just like tables, the grid isn’t limited by a particular content structure. This makes it possible to create a wider variety of website layouts than would be practical with tables alone.</p><h3>Grid Layout</h3><p>The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.</p><h3>How to Use CSS Grid</h3><p>if you want to set up a grid layout, you must create a parent div element(the grid container) and one or more child div elements (the grid items).</p><p>Setting the display property of an HTML element makes it a grid container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATiiSsk6BQOrgVL4T36u7Q.png" /></figure><p>Grid items are the direct children of the grid container. They are arranged vertically into columns and horizontally into rows.</p><p>The space between a row and a column is called a gap. You can adjust the gap using these properties:</p><ul><li><strong>grid-column-gap, which defines the gap between columns;</strong></li><li><strong>grid-row-gap, which defines the gap between rows; or</strong></li><li><strong>grid-gap, which is a shorthand property for grid-column-gap and grid-row-gap</strong></li></ul><h3>Grid Container</h3><p>Create a grid container by setting the display property with a value of grid or inline-grid. All direct children of grid containers become grid items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*RFy8Kdjdhk3Bxt6VmjZ4-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*lM4QUP9TZGTXIFiaJ84ncw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*14FW2QSeMxgRZ3TtjyJ4vw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/1*kNgTmWz160ww8drmR_ibcw.png" /></figure><p>When learning the various parts of the Grid Layout specification, it’s useful to remember which features are for the grid container and which are for the grid items.</p><p>In this CSS Grid tutorial, I’ll first cover the properties you would apply to the grid container. These are as follows:</p><ul><li>grid-template-rows</li><li>grid-template-columns</li><li>grid-template-area</li></ul><h3>Explicit Grid</h3><p>Explicitly set a grid by creating columns and rows with the grid -template-columns and grid-template-rows properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*yCFBY_aRXFb4-r-kZxpdXw.png" /></figure><p>A row track is created for each value specified for grid-template-rows. Track size values can be any non-negative, length value (px, %, em, etc.)</p><p>Items 1 and 2 have fixed heights of 50px and 100px.</p><p>Because only 2 row tracks were defined, heights of items 3 and 4 are defined by the contents of each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*IfT5O7BN5DOj_E5spMvPsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*rMT4_VZVARs8vhmB5Tp9Vw.png" /></figure><p>Like rows, a column track is created for each value specified for grid-template-columns.</p><p>Items 4, 5 and 6 were placed on a new row track because only 3 column track sizes were defined; and because they were placed in column tracks 1, 2 and 3, their column sizes are equal to items 1, 2 and 3.</p><p>Grid items 1, 2 and 3 have fixed widths of 90px, 50px and 120px respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*3ijZZdTEgsjnJIu_EeyNAA.png" /></figure><p>#CSS #Grid #Design</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=404ebb22fe89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three JavaScript Functions You Need To Know]]></title>
            <link>https://divyanamdev.medium.com/three-javascript-functions-you-need-to-know-35efca7da2c9?source=rss-e5141317eba0------2</link>
            <guid isPermaLink="false">https://medium.com/p/35efca7da2c9</guid>
            <dc:creator><![CDATA[Divyanamdev]]></dc:creator>
            <pubDate>Sat, 28 Aug 2021 16:08:46 GMT</pubDate>
            <atom:updated>2021-08-28T16:15:34.727Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript Functions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lOy5NQpGZcm4_J0te2aAMg.png" /></figure><p>Hello Reader, this is my first blog on javascript functions , i hope you will get it useful.</p><h3>1. CallBack Function</h3><h4>If you’re familiar with programming, you already know what functions do and how to use them. But what is a callback function? Callback functions are an important part of JavaScript and once you understand how callbacks work, you’ll become much better in JavaScript.</h4><p>So in this post, I would like to help you to understand what callback functions are and how to use them in JavaScript by going through some examples.</p><h4>A callback is a function passed as an argument to another function.</h4><pre>function print(callback) {  <br>    callback();<br>}</pre><h4>Using a callback, you could call the calculator function (myCalculator) with a callback, and let the calculator function run the callback after the calculation is finished:</h4><h4>Example</h4><blockquote>function myDisplayer(some) {<br> document.getElementById(“demo”).innerHTML = some;<br>}</blockquote><blockquote>function myCalculator(num1, num2, myCallback) {<br> let sum = num1 + num2;<br> myCallback(sum);<br>}</blockquote><blockquote>myCalculator(5, 5, myDisplayer);</blockquote><p>In the example above, myDisplayer is the name of a function.</p><p>It is passed to myCalculator() as an argument.</p><h3>When to Use a Callback?</h3><p>The examples above are not very exciting.</p><p>They are simplified to teach you the callback syntax.</p><p>Where callbacks really shine are in asynchronous functions, where one function has to wait for another function (like waiting for a file to load).</p><h3>2. Closure</h3><p>A closure is a function that has access to its outer function scope even after the outer function has returned. This means a closure can remember and access variables and arguments of its outer function even after the function has finished</p><p>Before we dive into closures, let’s first understand the lexical scope.</p><h4>What is a Lexical Scope?</h4><p>A lexical scope or static scope in JavaScript refers to the accessibility of the variables, functions, and objects based on their physical location in the source code.</p><h4>Example</h4><pre>let a = &#39;global&#39;;  function outer() {<br>    let b = &#39;outer&#39;;    function inner() {<br>      let c = &#39;inner&#39;<br>      console.log(c);   // prints &#39;inner&#39;<br>      console.log(b);   // prints &#39;outer&#39;<br>      console.log(a);   // prints &#39;global&#39;<br>    }<br>    console.log(a);     // prints &#39;global&#39;<br>    console.log(b);     // prints &#39;outer&#39;<br>    inner();<br>  }<br>outer();<br>console.log(a);         // prints &#39;global&#39;</pre><p>Here the inner function can access the variables defined in its own scope, the outer function’s scope, and the global scope. And the outer function can access the variable defined in its own scope and the global scope.</p><h4>So a scope chain of the above code would be like this:</h4><blockquote>Global {<br> outer {<br> inner<br> }<br>}</blockquote><p>Notice that inner function is surrounded by the lexical scope of outer function which is, in turn, surrounded by the global scope. That’s why the inner function can access the variables defined in outer function and the global scope.</p><h3>3. Higher-Order Functions</h3><p>If you are learning JavaScript, you must have come across the term <em>Higher-Order Functions. A</em>lthough<em> </em>it may sound complicated, it isn’t.</p><p>What makes JavaScript suitable for functional programming is that it accepts Higher-Order Functions.</p><p>Higher-Order Functions are extensively used in JavaScript. If you have been programming in JavaScript for a while, you may have already used them without even knowing.</p><p>To fully understand this concept, you first have to understand what <em>Functional Programming</em> is and the concept of <em>First-Class Functions.</em></p><h3>What is Functional Programming</h3><p>In most simple term, Functional Programming is a form of programming in which you can pass functions as parameters to other functions and also return them as values. In functional programming, we think and code in terms of functions.</p><p>JavaScript, Haskell, Clojure, Scala, and Erlang are some of the languages that implement functional programming.</p><h3>First-Class Functions</h3><p>If you have been learning JavaScript, you may have heard that JavaScript treats functions as first-class citizens. That’s because in JavaScript or any other functional programming languages functions are objects.</p><p>In JavaScript functions are a special type of objects. They are Function objects.</p><h4>Example:</h4><pre>function greeting() {<br>  console.log(&#39;Hello World&#39;);<br>}// Invoking the function<br>greeting();  // prints &#39;Hello World&#39;</pre><h3>Passing Functions as Parameters</h3><p>We can pass functions as parameters to other functions.</p><h4>Example:</h4><pre>function formalGreeting() {<br>  console.log(&quot;How are you?&quot;);<br>}function casualGreeting() {<br>  console.log(&quot;What&#39;s up?&quot;);<br>}function greet(type, greetFormal, greetCasual) {<br>  if(type === &#39;formal&#39;) {<br>    greetFormal();<br>  } else if(type === &#39;casual&#39;) {<br>    greetCasual();<br>  }<br>}// prints &#39;What&#39;s up?&#39;<br>greet(&#39;casual&#39;, formalGreeting, casualGreeting);</pre><p>Higher order functions are functions that operate on other functions, either by taking them as arguments or by returning them. In simple words, A Higher-Order function is a function that receives a function as an argument or returns the function as output.</p><p>For example, Array.prototype.map, Array.prototype.filter and Array.prototype.reduce are some of the Higher-Order functions built into the language.</p><h3>Higher-Order Functions in Action</h3><p>Let’s take a look at some examples of built-in higher-order functions and see how it compares to solutions where we aren’t using Higher-Order Functions.</p><h3>Array.prototype.map</h3><p>The map() method creates a new array by calling the callback function provided as an argument on every element in the input array. The map() method will take every returned value from the callback function and creates a new array using those values.</p><p>The callback function passed to the map() method accepts 3 arguments: element, index, and array.</p><p>If you find this post helpful then please like and comment on this post .</p><p>#JavaScript # Function</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35efca7da2c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>