<?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 Dulanjan chanaka on Medium]]></title>
        <description><![CDATA[Stories by Dulanjan chanaka on Medium]]></description>
        <link>https://medium.com/@dulanjanchanaka?source=rss-218ca8c33e6b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Rd9wGK1tBy8C-ykox42HNg.jpeg</url>
            <title>Stories by Dulanjan chanaka on Medium</title>
            <link>https://medium.com/@dulanjanchanaka?source=rss-218ca8c33e6b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:21:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dulanjanchanaka/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[Dynamic Routing in React.js]]></title>
            <link>https://medium.com/@dulanjanchanaka/dynamic-routing-in-react-js-2f23888c361f?source=rss-218ca8c33e6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f23888c361f</guid>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Dulanjan chanaka]]></dc:creator>
            <pubDate>Wed, 14 Jun 2023 15:44:44 GMT</pubDate>
            <atom:updated>2023-06-14T15:44:44.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="cover image" src="https://cdn-images-1.medium.com/max/801/1*0hMvZ2a6pbA07eeS_tLeag.jpeg" /></figure><h4>Introduction</h4><p>Dynamic routing is a powerful technique used in web development to handle navigation and rendering of pages based on changing parameters. Unlike traditional static routing, where pages are created and rendered component by component, dynamic routing allows for more flexible and efficient handling of complex app scenarios. In this article, we will explore dynamic routing using an example from an e-commerce app, demonstrating how it can be implemented in practice.</p><h4>Dynamic Routes in Action</h4><p>To illustrate dynamic routing, let’s consider an e-commerce app. Normally, pages in a web app are created and rendered by moving through different components. However, in the case of an e-commerce app, creating pages for each individual product is not practical. This is where dynamic routing comes in handy.</p><p>In our example, we will use the popular React framework and the react-router-dom library for routing. We’ll start by importing the necessary components into our main App.js file:</p><pre>import { BrowserRouter, Routes, Route } from &quot;react-router-dom&quot;;<br>import Home from &quot;./Home&quot;;<br>import Product from &quot;./Products&quot;;</pre><p>Next, we’ll define our routes using the Routes and Route components provided by react-router-dom:</p><pre>const App = () =&gt; {<br>  return (<br>    &lt;BrowserRouter&gt;<br>      &lt;Routes&gt;<br>        &lt;Route path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;<br>        &lt;Route path=&quot;/product/:productId&quot; element={&lt;Product /&gt;} /&gt;<br>      &lt;/Routes&gt;<br>    &lt;/BrowserRouter&gt;<br>  );<br>}</pre><p>Note the slight modification in the route path for the product page. We’ve added /:productId to indicate that this part of the URL will be dynamic and represent the product&#39;s unique identifier.</p><p>In the Product component, we can access the productId parameter using the useParams hook provided by react-router-dom:</p><pre>import { useParams } from &quot;react-router-dom&quot;;<br><br>const Product = () =&gt; {<br>  const { productId } = useParams();<br>  console.log(productId);<br>  <br>  return &lt;div&gt;Product&lt;/div&gt;;<br>}</pre><p>Here, we extract the productId from the URL parameters using object destructuring and log it to the console for verification. This way, we can access the specific product ID for fetching relevant data or rendering the product details on the page.</p><p>To fetch data based on the dynamic parameter, we can utilize the useEffect hook:</p><pre>import { useParams, useEffect } from &quot;react-router-dom&quot;;<br><br>const Product = () =&gt; {<br>  const { productId } = useParams();<br>  <br>  useEffect(() =&gt; {<br>    // Perform data fetching based on productId<br>  }, [productId]);<br>  <br>  return &lt;div&gt;Product&lt;/div&gt;;<br>}</pre><p>By including productId in the dependency array of useEffect, we ensure that the effect is executed and the component is re-rendered whenever the productId changes. This enables us to fetch updated data from a database or an API endpoint and dynamically render the content on the product page.</p><h4>Wrapping Up</h4><p>In this article, we explored the concept of dynamic routing and its practical implementation in a React app. We learned how to set up dynamic routes using the react-router-dom library, extract URL parameters with useParams, and fetch relevant data based on those parameters using useEffect. Dynamic routing provides a flexible and efficient way to handle complex app scenarios, such as rendering individual product pages in an e-commerce app.</p><p>we hope you found this article informative and helpful in understanding dynamic routing in web development.</p><p>Thank you all for reading…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f23888c361f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Array and Object in Javascript]]></title>
            <link>https://medium.com/@dulanjanchanaka/array-and-object-in-javascript-5d2bffff3098?source=rss-218ca8c33e6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d2bffff3098</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[objects]]></category>
            <dc:creator><![CDATA[Dulanjan chanaka]]></dc:creator>
            <pubDate>Mon, 08 May 2023 19:17:30 GMT</pubDate>
            <atom:updated>2023-06-14T09:16:36.343Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*BUrXdG7GkVlPbNPKoGU_4w.jpeg" /></figure><h3><strong>Array</strong></h3><p>Let’s talk about arrays first. An array is created in the same way as a variable is created using `var` , `let` or `const`.</p><p>An array in JavaScript is like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59c97ae5ae570972f674aa335fcf7588/href">https://medium.com/media/59c97ae5ae570972f674aa335fcf7588/href</a></iframe><p>Any data type can be stored in an array. Even an array can be stored inside an array. The data items in an array are called elements. Data items in the array are accessed by their index.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b810e68d923a1777d45feed59870cf7e/href">https://medium.com/media/b810e68d923a1777d45feed59870cf7e/href</a></iframe><p>You can also add two arrays. It is called array concatenation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bbe4a72bd98500773c25faa97a1c3b4/href">https://medium.com/media/8bbe4a72bd98500773c25faa97a1c3b4/href</a></iframe><p>Even a string can be separated into elements and stored in an array. It is indicated in () with what using to allocate it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/219a345a1269ccfdababe10267ca2e26/href">https://medium.com/media/219a345a1269ccfdababe10267ca2e26/href</a></iframe><p>In this way, data can be replaced using the index of an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93c357728dfbb8bcab0aa9077ccac905/href">https://medium.com/media/93c357728dfbb8bcab0aa9077ccac905/href</a></iframe><h3><strong>Inserting and removing elements from an array</strong></h3><p>If you want to enter data as the first element of an array, this method is used</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/447e70ef3ee8f58a5f0067ec5c6e27da/href">https://medium.com/media/447e70ef3ee8f58a5f0067ec5c6e27da/href</a></iframe><p>If you want to enter data as the last element of an array, this method is used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/498849edc8d51fe06d4bee021905a5a2/href">https://medium.com/media/498849edc8d51fe06d4bee021905a5a2/href</a></iframe><p>If you want to remove the first element of an array, this method is used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0db9783f68ffd8ed2cc3428b0925dad6/href">https://medium.com/media/0db9783f68ffd8ed2cc3428b0925dad6/href</a></iframe><p>If you want to remove the last element of an array, this method is used</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e72f9a666e20b2a64b7849f9bc1a0c7/href">https://medium.com/media/5e72f9a666e20b2a64b7849f9bc1a0c7/href</a></iframe><p>Even if a value is assigned to an array, an empty element can be created if the number of elements is less than the specified value. When using the unshift, push method, the creation of an empty element is avoided. And by missing an element in the array, assigning a new value is also avoided.</p><p>A method that can easily enter data into an array mentioned earlier has been done by using loop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b37d82575f6a923908a8dcc9c83cb695/href">https://medium.com/media/b37d82575f6a923908a8dcc9c83cb695/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*rnHwGtpaZDGyiuBXEKv0UA.png" /></figure><p>Destructuring the array can be done in the following way. It is easy to use the data of an array outside.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed7f61006f9728f5f395ff98f7570ae6/href">https://medium.com/media/ed7f61006f9728f5f395ff98f7570ae6/href</a></iframe><h3><strong>Object</strong></h3><p>Any data type can be stored in an object as well as in an array. Here it is stored as a key value pair. Even an array can be stored in an object. Even an object can be stored in an object. Even if an object has several similar values, the key cannot be duplicate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50874dc8f13cf9f9153534dc27a0a006/href">https://medium.com/media/50874dc8f13cf9f9153534dc27a0a006/href</a></iframe><p>Data access in an object can be done in this way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29cc91298f32917ec6e0c0efcd54a723/href">https://medium.com/media/29cc91298f32917ec6e0c0efcd54a723/href</a></iframe><p>This method can be used to insert new data into an object</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6b3fe50bef2617e9ee4806263fc3954/href">https://medium.com/media/e6b3fe50bef2617e9ee4806263fc3954/href</a></iframe><p>Destructuring an object</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43f234d08ab420cd45c16f3487024c92/href">https://medium.com/media/43f234d08ab420cd45c16f3487024c92/href</a></iframe><p>It makes it easy to select only the necessary data in an object and use it externally.</p><p>When creating a variable, a separate space is allocated in the memory to store it. The value of an existing variable is assigned to another new variable and stored separately in the memory automatically. But when assigning the value of an object or array to a new object or array, only a reference is made to the place where the value is stored earlier. It is not stored separately in the memory as a new object or array.</p><p>The spread operator is used as a solution. Here, the data of a previously created array or object can be assigned to a new array or object and stored separately in the memory. That way, their data can be changed separately.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f649cd13ce5f33f133696671899d0944/href">https://medium.com/media/f649cd13ce5f33f133696671899d0944/href</a></iframe><p>thank you….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d2bffff3098" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>