<?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 Sushil Kundu on Medium]]></title>
        <description><![CDATA[Stories by Sushil Kundu on Medium]]></description>
        <link>https://medium.com/@sushilkundu143?source=rss-4a1cdf94a73e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WucTO1uXGOlZPpmVNo-xCQ.jpeg</url>
            <title>Stories by Sushil Kundu on Medium</title>
            <link>https://medium.com/@sushilkundu143?source=rss-4a1cdf94a73e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:21:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sushilkundu143/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[Implementing A/B Testing in a React App Using Split.io]]></title>
            <link>https://medium.com/@sushilkundu143/implementing-a-b-testing-in-a-react-app-using-split-io-8864e5399cee?source=rss-4a1cdf94a73e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8864e5399cee</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[a-b-testing]]></category>
            <category><![CDATA[ab-testing]]></category>
            <category><![CDATA[split-testing]]></category>
            <category><![CDATA[search-engine-optimizaion]]></category>
            <dc:creator><![CDATA[Sushil Kundu]]></dc:creator>
            <pubDate>Wed, 29 May 2024 06:41:25 GMT</pubDate>
            <atom:updated>2024-06-04T21:18:51.919Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is A/B Testing?</h3><p>A/B testing, also known as split testing or bucket testing, is a method of comparing two versions of a webpage or app against each other to determine which one performs better. By showing the two variants (A and B) to different segments of users at the same time, analysts can measure which version leads to more desired actions, such as conversions, clicks, or purchases.</p><h3>Steps in A/B Testing:</h3><ol><li><strong>Identify Goals</strong>: Determine the metrics you want to improve, such as click-through rates, conversion rates, etc.</li><li><strong>Create Variations</strong>: Develop two versions of the element you want to test (e.g., two different button designs).</li><li><strong>Split Traffic</strong>: Randomly assign visitors to the control group (A) or the variation group (B).</li><li><strong>Run the Test</strong>: Collect data over a specified period.</li><li><strong>Analyze Results</strong>: Use statistical analysis to determine which version performed better.</li><li><strong>Implement Changes</strong>: Deploy the winning variation based on the results.</li></ol><h3>Need for A/B Testing</h3><ol><li><strong>Data-Driven Decisions</strong>: Allows companies to make informed decisions based on actual user behavior and data rather than assumptions.</li><li><strong>Optimize Performance</strong>: Helps improve key metrics such as conversion rates, engagement, and user satisfaction.</li><li><strong>Risk Mitigation</strong>: Reduces the risk of implementing changes that might negatively impact the user experience or business metrics.</li><li><strong>User Experience</strong>: Enhances the user experience by determining which variations of design, copy, or functionality users prefer.</li><li><strong>Competitive Advantage</strong>: Continuous optimization can provide a competitive edge by ensuring that the best possible user experience is delivered.</li></ol><h3>A/B Testing with Split.io:</h3><p>A/B testing is an essential practice for understanding user preferences and improving user experience. Split.io offers a robust platform for feature flagging and A/B testing. In this blog post, we’ll walk through implementing A/B testing in a React application using Split.io, providing a clear example to get you started.</p><h3><strong>Step-by-Step Guide:</strong></h3><h4>Step 1: Set Up Split.io</h4><p>First, ensure you have a Split.io account and have created a feature flag named abtestingdemo with treatments on and off. This setup will allow us to toggle between two variants in our React app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqRCfqM8zg6k6lYP756ECg.png" /></figure><h4>Step 2: Install Dependencies</h4><p>Install the necessary Split.io React SDK in your React project:</p><pre>npm install @splitsoftware/splitio-react uuid</pre><h4>Step 3: Configure Split.io</h4><p>Create a configuration file for Split.io. This file includes the authorization key and user identification logic.</p><p><strong>Config.js</strong></p><pre>import getUserKey from &quot;./src/utils/userKey&quot;;<br>const CONFIG = {<br>  core: {<br>    authorizationKey: &quot;YOUR_SPLIT_API_KEY&quot;, // Replace with your actual Split API key<br>    key: getUserKey(),<br>  },<br>};<br>export default CONFIG;</pre><p><strong>userKey.js</strong></p><pre>import {<br>  v4 as uuidv4<br>} from &quot;uuid&quot;;<br>const getUserKey = () =&gt; {<br>  let userKey = localStorage.getItem(&quot;user_key&quot;);<br>  if (!userKey) {<br>    userKey = uuidv4();<br>    localStorage.setItem(&quot;user_key&quot;, userKey);<br>  }<br>  return userKey;<br>};<br>export default getUserKey;</pre><h4>Step 4: Create Variant Components</h4><p>Create two simple components representing the two variants of your A/B test.</p><p><strong>VariantA.jsx</strong></p><pre>import React from &quot;react&quot;;<br>const VariantA = () =&gt; (<br>  &lt;div&gt;<br>     &lt;h1&gt;Variant A&lt;/h1&gt; <br>    &lt;p&gt;This is variant A of the experiment.&lt;/p&gt; <br>  &lt;/div&gt;<br>);<br>export default VariantA;</pre><p><strong>VariantB.jsx</strong></p><pre>import React from &quot;react&quot;;<br>const VariantB = () =&gt; (<br>  &lt;div&gt;<br>    &lt;h1&gt;Variant B&lt;/h1&gt;<br>    &lt;p&gt;This is variant B of the experiment.&lt;/p&gt;<br>  &lt;/div&gt;<br>);<br>export default VariantB;</pre><h4>Step 5: Create the Experiment Component</h4><p>The Experiment component uses Split.io to decide which variant to display.</p><p><strong>Experiment.jsx</strong></p><pre>import React from &quot;react&quot;;<br>import VariantA from &quot;./VariantA&quot;;<br>import VariantB from &quot;./VariantB&quot;;<br>import { useSplitTreatments } from &quot;@splitsoftware/splitio-react&quot;;<br>const Experiment = () =&gt; {<br>  const { treatments, isReady } = useSplitTreatments({<br>    names: [&quot;abtestingdemo&quot;],<br>  });<br>  if (!isReady) return &lt;div&gt;Loading SDK …&lt;/div&gt;;<br>  if (treatments.abtestingdemo.treatment === &quot;on&quot;) {<br>    return &lt;VariantA /&gt;;<br>  } else if (treatments.abtestingdemo.treatment === &quot;off&quot;) {<br>    return &lt;VariantB /&gt;;<br>  } else {<br>    return &lt;div&gt;Loading…&lt;/div&gt;;<br>  }<br>};<br>export default Experiment;</pre><h4>Step 6: Set Up the Main Application</h4><p>Wrap your main application with the Split.io provider and include the Experiment component.</p><p><strong>App.jsx</strong></p><pre>import React from &quot;react&quot;;<br>import Experiment from &quot;./components/Experiment&quot;;<br>import { SplitFactoryProvider } from &quot;@splitsoftware/splitio-react&quot;;<br>import CONFIG from &quot;../splitConfig&quot;;<br>const App = () =&gt; {<br>  return (<br>    &lt;div&gt;<br>       &lt;h1&gt;Welcome to My App&lt;/h1&gt; <br>      &lt;SplitFactoryProvider config={CONFIG}&gt;<br>         &lt;Experiment /&gt; <br>      &lt;/SplitFactoryProvider&gt;<br>       <br>    &lt;/div&gt;<br>  );<br>};<br>export default App;</pre><h4>Step 7: Render the App</h4><p>Finally, render the App component in your root file.</p><p><strong>Index.jsx</strong></p><pre>import { StrictMode } from &quot;react&quot;;<br>import { createRoot } from &quot;react-dom/client&quot;;<br>import App from &quot;./App&quot;;<br>const rootElement = document.getElementById(&quot;root&quot;);<br>const root = createRoot(rootElement);<br>root.render(<br>  &lt;StrictMode&gt;<br>     &lt;App /&gt; <br>  &lt;/StrictMode&gt;,<br>);</pre><p><strong>Explanation:</strong></p><p><strong>1.Split.io Configuration:</strong></p><p>The Config.js file sets up the Split.io configuration, including the authorization key and a unique user key generated by userKey.js. The user key ensures that the treatment assignment is consistent for each user.</p><p><strong>2. Variant Components:</strong></p><p>VariantA.jsx and VariantB.jsx represent the two different user experiences you want to test.</p><p><strong>3. Experiment Component:</strong></p><p>Experiment.jsx uses the useSplitTreatments hook from the Split.io React SDK to fetch the current treatment for abtestingdemo.</p><p>Based on the treatment, it conditionally renders either VariantA or VariantB.</p><p><strong>4. Main Application Setup:</strong></p><p>App.jsx wraps the application in the SplitFactoryProvider, passing in the Split.io configuration.</p><p>It includes the Experiment component to perform the A/B test.</p><p><strong>5. Rendering the Application:</strong></p><p>Index.jsx renders the App component inside a StrictMode wrapper for better debugging and more robust development.</p><p>Here is preview when abtestingdemo.treatment === “off”</p><figure><img alt="AB Testing preview result with Split.io when abtestingdemo.treatment === “off”" src="https://cdn-images-1.medium.com/max/1024/1*3juxkBY3GpOvOjujP2H-8Q.png" /></figure><p>Here is preview when abtestingdemo.treatment === “on”</p><figure><img alt="AB Testing preview result with Split.io when abtestingdemo.treatment === “on”" src="https://cdn-images-1.medium.com/max/1024/1*ejJ84OSKAFnrDB9T-KYu5g.png" /></figure><h3>Conclusion</h3><p>By following this guide, you can implement A/B testing in your React application using Split.io. This setup allows you to test different user experiences and gather valuable insights to drive data-driven decisions. Whether you’re optimizing a button color or testing a new feature, Split.io provides a scalable and flexible solution for your experimentation needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8864e5399cee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Dynamic Forms with React Hook Form and React]]></title>
            <link>https://medium.com/@sushilkundu143/building-dynamic-forms-with-react-hook-form-and-react-66a2f6a89d9?source=rss-4a1cdf94a73e------2</link>
            <guid isPermaLink="false">https://medium.com/p/66a2f6a89d9</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook-form]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Sushil Kundu]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 18:35:16 GMT</pubDate>
            <atom:updated>2023-06-25T18:50:59.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d2-9LI0eWktCQISp.png" /></figure><p><strong><em>Conclusion:</em></strong></p><p>In this technical blog, we explored the process of creating a dynamic form with a JSON schema and handling form controls and validation using React Hook Form and React.</p><p><strong><em>Key Points:</em></strong></p><ol><li>React Hook Form is a powerful library that simplifies form management in React applications. It offers efficient performance and streamlined form validation capabilities.</li><li>A JSON schema provides a structured approach to define form fields, their types, labels, and validation rules. This allows for easy customization and flexibility in form creation.</li><li>By looping through the JSON schema and utilizing React Hook Form, we can dynamically render form controls based on their defined types. This approach reduces repetitive code and enhances maintainability.</li><li>React Hook Form simplifies form validation by seamlessly integrating with the defined validation rules in the JSON schema. It automatically handles error messages and validation feedback.</li><li>The process of handling form submission is straightforward with React Hook Form. The handleSubmit function captures form data, and the library provides built-in error handling and validation.</li></ol><p>In conclusion, by leveraging the power of React Hook Form and utilizing a JSON schema, we can create dynamic forms that offer enhanced user experiences and efficient form management. With this approach, developers can easily define and customize form fields, handle form controls, and implement robust validation. React Hook Form simplifies the process, reducing the complexity of form development and allowing for a more seamless user interaction. By following the principles outlined in this blog, developers can confidently build dynamic forms in their React applications, improving usability and productivity.</p><p><strong><em>Support Points:</em></strong></p><p><strong><em>React Hook Form Benefits:</em></strong></p><ul><li>Enhanced performance through minimal re-renders and uncontrolled components.</li><li>Streamlined form validation with intuitive rules and error handling.</li><li>Seamless integration with existing UI libraries and frameworks.</li></ul><p><strong><em>JSON-based Schema:</em></strong></p><ul><li>The schema object defines form fields, including types, labels, and validation rules.</li><li>Validation rules can include requirements like field presence, minimum length, pattern matching, and more.</li></ul><p><strong><em>Dynamic Form Generation:</em></strong></p><ul><li>Looping through the schema allows us to dynamically render form controls based on field types.</li><li>A switch statement helps us determine the appropriate form control based on the field type.</li></ul><p><strong><em>Form Validation:</em></strong></p><ul><li>React Hook Form simplifies form validation by utilizing the validation rules defined within the schema.</li><li>Errors are automatically displayed based on validation rules, providing a seamless user experience.</li></ul><p><strong><em>Handling Form Submission:</em></strong></p><ul><li>React Hook Form’s handleSubmit function captures and processes form data upon submission.</li><li>Error handling is built-in, allowing easy display of validation errors.</li></ul><p><strong><em>Example with Code:</em></strong></p><pre>const schema = {<br>  firstName: {<br>    label: &#39;First Name&#39;,<br>    type: &#39;text&#39;,<br>    validation: {<br>      required: &#39;First Name is required&#39;,<br>      minLength: {<br>        value: 3,<br>        message: &#39;First Name should have at least 3 characters&#39;,<br>      },<br>    },<br>  },<br>  lastName: {<br>    label: &#39;Last Name&#39;,<br>    type: &#39;text&#39;,<br>    validation: {<br>      required: &#39;Last Name is required&#39;,<br>    },<br>  },<br>  email: {<br>    label: &#39;Email&#39;,<br>    type: &#39;email&#39;,<br>    validation: {<br>      required: &#39;Email is required&#39;,<br>      pattern: {<br>        value: /^\S+@\S+$/i,<br>        message: &#39;Invalid email address&#39;,<br>      },<br>    },<br>  },<br>};<br><br>export default schema;</pre><pre>import React from &#39;react&#39;;<br>import { useForm } from &#39;react-hook-form&#39;;<br>import schema from &quot;./schema&quot;;<br><br>const DynamicForm = () =&gt; {<br>  const { register, handleSubmit, errors, setValue } = useForm();<br><br>  const onSubmit = (data) =&gt; {<br>    console.log(data);<br>  };<br><br>  const handleInputChange = (event) =&gt; {<br>    const { name, value } = event.target;<br>    setValue(name, value);<br>  };<br><br>  const renderFormControl = (key, field) =&gt; {<br>    switch (field.type) {<br>      case &#39;text&#39;:<br>      case &#39;email&#39;:<br>      case &#39;number&#39;:<br>      case &#39;password&#39;:<br>        return (<br>          &lt;div key={key}&gt;<br>            &lt;label&gt;{field.label}&lt;/label&gt;<br>            &lt;input<br>              type={field.type}<br>              name={key}<br>              ref={register(field.validation)}<br>              onChange={handleInputChange}<br>            /&gt;<br>            {errors[key] &amp;&amp; &lt;span&gt;{errors[key].message}&lt;/span&gt;}<br>          &lt;/div&gt;<br>        );<br>      case &#39;select&#39;:<br>        return (<br>          &lt;div key={key}&gt;<br>            &lt;label&gt;{field.label}&lt;/label&gt;<br>            &lt;select<br>              name={key}<br>              ref={register(field.validation)}<br>              onChange={handleInputChange}<br>            &gt;<br>              {/* Options for select dropdown */}<br>            &lt;/select&gt;<br>            {errors[key] &amp;&amp; &lt;span&gt;{errors[key].message}&lt;/span&gt;}<br>          &lt;/div&gt;<br>        );<br>      case &#39;checkbox&#39;:<br>        return (<br>          &lt;div key={key}&gt;<br>            &lt;label&gt;<br>              &lt;input<br>                type=&quot;checkbox&quot;<br>                name={key}<br>                ref={register(field.validation)}<br>                onChange={handleInputChange}<br>              /&gt;<br>              {field.label}<br>            &lt;/label&gt;<br>            {errors[key] &amp;&amp; &lt;span&gt;{errors[key].message}&lt;/span&gt;}<br>          &lt;/div&gt;<br>        );<br>      default:<br>        return null;<br>    }<br>  };<br><br>  return (<br>    &lt;form onSubmit={handleSubmit(onSubmit)}&gt;<br>      {/* Render form controls dynamically */}<br>      {Object.entries(schema).map(([key, field]) =&gt;<br>        renderFormControl(key, field)<br>      )}<br>      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>  );<br>};<br><br>export default DynamicForm;</pre><p>In the modified code, the handleInputChange function is added to handle the onChange event for the form fields. This function extracts the name and value from the event target and uses the setValue function provided by React Hook Form to update the form field&#39;s value. By updating the form field value on each change, React Hook Form will automatically handle the validation and error messages based on the defined validation rules in the schema.</p><p><strong><em>Takeaway:</em></strong></p><p>Building dynamic forms using React Hook Form and React provides a powerful and efficient way to handle form management and validation. By leveraging a JSON-based schema and utilizing React Hook Form’s features, we can create flexible and interactive forms with ease. Remember to define the schema, loop through it to render form controls dynamically, handle form validation, and process form submission using React Hook Form’s handleSubmit function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66a2f6a89d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Code Splitting with Loadable Component and React Router 6]]></title>
            <link>https://medium.com/@sushilkundu143/implementing-code-splitting-with-loadable-component-and-react-router-6-9e3e7c7a8c2e?source=rss-4a1cdf94a73e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e3e7c7a8c2e</guid>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[react-loadable]]></category>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[loadable-component]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sushil Kundu]]></dc:creator>
            <pubDate>Thu, 22 Jun 2023 06:36:32 GMT</pubDate>
            <atom:updated>2023-06-22T06:36:32.259Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*8ZxLMohY4ZJtahy4.png" /></figure><p><strong><em>Introduction:</em></strong></p><p>In modern web development, optimizing the performance of React applications is crucial for delivering a smooth user experience. Code splitting is an effective technique that allows us to load only the necessary JavaScript code when required. In this technical blog post, we will explore how to implement code splitting using Loadable Component and React Router 6. We will cover dynamic imports, fallback UI with suspense, specifying chunk names, and provide examples for home, about, login, and signup routes.</p><p><strong><em>Conclusion:</em></strong></p><p>Loadable Component and React Router 6 are powerful tools for implementing code splitting in React applications. By utilizing dynamic imports, providing fallback UI with suspense, and specifying chunk names, we can significantly enhance our application’s performance. Implementing code splitting with Loadable Component and React Router 6 allows for efficient loading of necessary code chunks, resulting in faster initial page loads and improved user experiences.</p><p><strong><em>Key Points:</em></strong></p><p>a. Code splitting optimizes performance by loading only necessary code. <br>b. Loadable Component simplifies code splitting implementation in React.</p><p>c. React Router 6 provides a convenient way to define and manage routes.</p><p>d. Dynamic imports asynchronously load components when needed.</p><p>e. Fallback UI with suspense ensures a better user experience during component loading.</p><p>f. Specifying chunk names helps with debugging and tracking loaded code chunks.</p><p><strong><em>Support Points with Detailed Information:</em></strong></p><p>a. Dynamic Imports: Dynamic imports allow us to load components asynchronously when they are needed in our application. We can leverage Loadable Component to easily implement dynamic imports in React. Here’s an example of dynamically importing a component:</p><pre>import loadable from &#39;@loadable/component&#39;;<br><br>const Home = loadable(() =&gt; import(&#39;./Home&#39;));<br>const About = loadable(() =&gt; import(&#39;./About&#39;));<br>const Login = loadable(() =&gt; import(&#39;./Login&#39;));<br>const Signup = loadable(() =&gt; import(&#39;./Signup&#39;));</pre><p>b. Fallback UI with Suspense: While the dynamically imported components are being loaded, we can provide a fallback UI to maintain a seamless user experience. By using React’s Suspense component, we can achieve this easily. Here&#39;s an example:</p><pre>import loadable from &#39;@loadable/component&#39;;<br>import { Suspense } from &#39;react&#39;;<br><br>const Home = loadable(() =&gt; import(&#39;./Home&#39;));<br>const About = loadable(() =&gt; import(&#39;./About&#39;));<br>const Login = loadable(() =&gt; import(&#39;./Login&#39;));<br>const Signup = loadable(() =&gt; import(&#39;./Signup&#39;));<br><br>function App() {<br>  return (<br>    &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>      &lt;Router&gt;<br>        &lt;Routes&gt;<br>          &lt;Route path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;<br>          &lt;Route path=&quot;/about&quot; element={&lt;About /&gt;} /&gt;<br>          &lt;Route path=&quot;/login&quot; element={&lt;Login /&gt;} /&gt;<br>          &lt;Route path=&quot;/signup&quot; element={&lt;Signup /&gt;} /&gt;<br>        &lt;/Routes&gt;<br>      &lt;/Router&gt;<br>    &lt;/Suspense&gt;<br>  );<br>}</pre><p>c. Specifying Chunk Names: Assigning meaningful names to code chunks is beneficial for debugging and tracking purposes. Loadable Component allows us to specify chunk names using the webpackChunkName comment. Here&#39;s an example:</p><pre>import loadable from &#39;@loadable/component&#39;;<br><br>const Home = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;home&#39; */ &#39;./Home&#39;)<br>);<br>const About = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;about&#39; */ &#39;./About&#39;)<br>);<br>const Login = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;login&#39; */ &#39;./Login&#39;)<br>);<br>const Signup = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;signup&#39; */ &#39;./Signup&#39;)<br>);</pre><p><strong><em>Example with Explanation:</em></strong></p><p>Let’s consider a scenario where we have a React application with four routes: home, about, login, and signup. We can implement code splitting for each route using Loadable Component (using Suspense, ChunkName, dynamic Import &amp; fallback UI) and React Router 6.</p><pre>import loadable from &#39;@loadable/component&#39;;<br>import { Suspense } from &#39;react&#39;;<br>import { BrowserRouter as Router, Routes, Route } from &#39;react-router-dom&#39;;<br><br>const Home = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;home&#39; */ &#39;./Home&#39;)<br>);<br>const About = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;about&#39; */ &#39;./About&#39;)<br>);<br>const Login = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;login&#39; */ &#39;./Login&#39;)<br>);<br>const Signup = loadable(() =&gt;<br>  import(/* webpackChunkName: &#39;signup&#39; */ &#39;./Signup&#39;)<br>);<br><br>function App() {<br>  return (<br>    &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>      &lt;Router&gt;<br>        &lt;Routes&gt;<br>          &lt;Route path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;<br>          &lt;Route path=&quot;/about&quot; element={&lt;About /&gt;} /&gt;<br>          &lt;Route path=&quot;/login&quot; element={&lt;Login /&gt;} /&gt;<br>          &lt;Route path=&quot;/signup&quot; element={&lt;Signup /&gt;} /&gt;<br>        &lt;/Routes&gt;<br>      &lt;/Router&gt;<br>    &lt;/Suspense&gt;<br>  );<br>}</pre><p>The code imports the necessary modules: loadable from @loadable/component, Suspense from react, and BrowserRouter, Routes, and Route from react-router-dom.</p><p>loadable is a function provided by Loadable Component that allows us to dynamically import components. Here, we use it to create separate chunks for each component: Home, About, Login, and Signup. Each component is imported dynamically using the import function, and we specify the chunk names using the webpackChunkName comment. Make sure the file paths for the components are correct.</p><p>The App function is the root component of the application.</p><p>&lt;Suspense&gt; is a component provided by React that allows us to specify a fallback UI while the dynamic components are being loaded. In this case, we provide a simple fallback UI with the text &quot;Loading...&quot; wrapped in a &lt;div&gt;.</p><p>&lt;Router&gt; sets up the routing functionality for the application using React Router.</p><p>&lt;Routes&gt; is used to define the routes within the application.</p><p>&lt;Route&gt; is used to define individual routes. Each &lt;Route&gt; specifies a path attribute and an element attribute, which represents the component to render when the corresponding route is accessed. Here, we map the routes to the dynamically imported components Home, About, Login, and Signup.</p><p>Make sure to install the necessary dependencies (@loadable/component, react-router-dom, and react) and import them correctly in your project.</p><p><strong><em>Takeaway:</em></strong></p><p>Loadable Component combined with React Router 6 offers a powerful solution for implementing code splitting in React applications. By utilizing dynamic imports, providing fallback UI with suspense, and specifying chunk names, we can significantly optimize performance and deliver faster initial page loads. Proper code splitting helps improve user experiences by ensuring that only the necessary code is loaded, resulting in reduced load times and enhanced responsiveness.</p><p><strong><em>Conclusion:</em></strong></p><p>In this technical blog post, we explored the implementation of code splitting using Loadable Component and React Router 6 in a React application. We discussed the key concepts of dynamic imports, fallback UI with suspense, and specifying chunk names. By following the provided examples and leveraging these powerful tools, developers can optimize the performance of their React applications, delivering faster and more efficient user experiences</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e3e7c7a8c2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Working with Route Parameters and Query Parameters in React Router 6]]></title>
            <link>https://medium.com/@sushilkundu143/a-comprehensive-guide-to-working-with-route-parameters-and-query-parameters-in-react-router-6-d40cf9b6f83?source=rss-4a1cdf94a73e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d40cf9b6f83</guid>
            <category><![CDATA[query-parameters]]></category>
            <category><![CDATA[route-param]]></category>
            <category><![CDATA[react-router-6]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-router]]></category>
            <dc:creator><![CDATA[Sushil Kundu]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 11:18:29 GMT</pubDate>
            <atom:updated>2023-06-22T04:21:28.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dz60XJYBtmGsTwyo.jpg" /></figure><p><strong><em>Introduction:</em></strong></p><ul><li>Overview of React Router 6 and its importance in building dynamic web applications.</li><li>Brief explanation of route parameters and query parameters.</li><li>Importance of understanding how to access and utilize route parameters and query parameters.</li></ul><p>I. Installation:</p><ul><li>Step-by-step instructions for installing React Router 6 using npm.</li><li>Mention the command: npm install react-router-dom@next.</li><li>Importance of installing the correct version for React Router 6 compatibility.</li></ul><p>II. Route Configuration:</p><ul><li>Explanation of the route configuration in React Router 6.</li><li>Introduction to the &lt;Routes&gt; component for setting up routes.</li><li>Explanation of the &lt;Route&gt; component for defining individual routes.</li><li>Emphasize the importance of proper route configuration.</li></ul><p>III. Accessing Route Parameters:</p><ul><li>Introduction to route parameters and their significance.</li><li>Brief explanation of the useParams hook in React Router 6.</li><li>Demonstration of how to import and utilize the useParams hook.</li><li>Example of accessing route parameters within a component.</li></ul><p>IV. Accessing Query Parameters:</p><ul><li>Introduction to query parameters and their purpose.</li><li>Explanation of the useSearchParams hook in React Router 6.</li><li>Demonstration of how to import and utilize the useSearchParams hook.</li><li>Example of accessing query parameters within a component.</li></ul><p>V. Example Usage:</p><ul><li>Walkthrough of an example scenario using route parameters and query parameters.</li><li>Step-by-step instructions for setting up route components with parameters.</li><li>Demonstration of linking to routes with parameters.</li><li>Showcase the utilization of route and query parameters within a component.</li></ul><p><strong><em>Deep Dive:</em></strong></p><p>In React Router 6, you can access both route parameters and query parameters using the same approach as described earlier. Here’s how you can get the values of both parameters when using the route parameter /user/:id and query parameter /example?id=${id}:</p><ol><li>Set up your route configuration and routes using the &lt;Routes&gt; component:</li></ol><pre>import { BrowserRouter as Router, Routes, Route, Link } from &quot;react-router-dom&quot;;<br>import User from &quot;./User&quot;;<br>import Example from &quot;./Example&quot;;<br><br>function App() {<br>  return (<br>    &lt;Router&gt;<br>      &lt;nav&gt;<br>        &lt;ul&gt;<br>          &lt;li&gt;<br>            &lt;Link to=&quot;/user/:id&quot;&gt;User&lt;/Link&gt;<br>          &lt;/li&gt;<br>          &lt;li&gt;<br>            &lt;Link to=&quot;/example?id=456&quot;&gt;Example&lt;/Link&gt;<br>          &lt;/li&gt;<br>        &lt;/ul&gt;<br>      &lt;/nav&gt;<br>      &lt;Routes&gt;<br>        &lt;Route path=&quot;/user/:id&quot; element={&lt;User /&gt;} /&gt;<br>        &lt;Route path=&quot;/example&quot; element={&lt;Example /&gt;} /&gt;<br>      &lt;/Routes&gt;<br>    &lt;/Router&gt;<br>  );<br>}<br><br>export default App;</pre><p>2. Access the route parameter and query parameter within your Example &amp; User component using the useParams and useSearchParams hooks, respectively:</p><pre>import { useParams} from &#39;react-router-dom&#39;;<br><br>function User() {<br>  const { id } = useParams();<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;User Component&lt;/h2&gt;<br>      &lt;p&gt;Route parameter &#39;id&#39; value: {id}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default User;</pre><pre><br>import { useSearchParams } from &quot;react-router-dom&quot;;<br><br>function Example() {<br>  const [searchParams] = useSearchParams();<br>  const queryParamId = searchParams.get(&quot;id&quot;);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Example Component&lt;/h2&gt;<br>      &lt;p&gt;Query parameter &#39;id&#39; value: {queryParamId}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Example;</pre><p>With the above route configuration, when you navigate to /user/123, the User component will be rendered, and you can access the value of the route parameter id using the useParams hook. Similarly, when you navigate to /example?id=456, the Example component will be rendered, and you can access both the route parameter id and the query parameter id using the useSearchParams hook, respectively. This allows you to extract and utilize the parameter values within each component for further processing or rendering.</p><p><strong><em>Conclusion:</em></strong></p><p>In this comprehensive guide, we explored the ins and outs of working with route parameters and query parameters in React Router 6. We covered the installation process, route configuration, and the importance of setting up routes correctly. Additionally, we delved into accessing both route parameters and query parameters using the useParams and useSearchParams hooks, respectively.</p><p>By leveraging the useParams hook, we easily accessed the value of the route parameter within our components. Similarly, with the useSearchParams hook, we retrieved and utilized the query parameters. We walked through example scenarios demonstrating how to set up route components with parameters and how to link to routes with parameters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d40cf9b6f83" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>