<?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: Shaogat Alam</title>
    <description>The latest articles on DEV Community by Shaogat Alam (@shaogat_alam_1e055e90254d).</description>
    <link>https://dev.to/shaogat_alam_1e055e90254d</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1699651%2Fb23aa545-6c6a-49da-80b5-3ad8101a11f4.jpg</url>
      <title>DEV Community: Shaogat Alam</title>
      <link>https://dev.to/shaogat_alam_1e055e90254d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shaogat_alam_1e055e90254d"/>
    <language>en</language>
    <item>
      <title>🛠️ Understanding the Relationship Between chunk() Size and fetchSize in Spring Batch 🔄</title>
      <dc:creator>Shaogat Alam</dc:creator>
      <pubDate>Wed, 11 Sep 2024 15:37:03 +0000</pubDate>
      <link>https://dev.to/shaogat_alam_1e055e90254d/understanding-the-relationship-between-chunk-size-and-fetchsize-in-spring-batch-28n3</link>
      <guid>https://dev.to/shaogat_alam_1e055e90254d/understanding-the-relationship-between-chunk-size-and-fetchsize-in-spring-batch-28n3</guid>
      <description>&lt;p&gt;In Spring Batch, the &lt;code&gt;chunk()&lt;/code&gt; size and &lt;code&gt;fetchSize&lt;/code&gt; in the &lt;code&gt;JdbcPagingItemReader&lt;/code&gt; serve different purposes. Here's how they interact and what happens when one is larger than the other:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;&lt;code&gt;chunk()&lt;/code&gt; Size (Chunk-Oriented Processing)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;chunk()&lt;/code&gt; size&lt;/strong&gt; defines the number of items that will be processed (read, processed, and written) in a single transaction.&lt;/li&gt;
&lt;li&gt;When the chunk size is reached, Spring Batch will commit the transaction, and a new chunk begins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;&lt;code&gt;fetchSize&lt;/code&gt; (Database Fetch Size)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;fetchSize&lt;/code&gt;&lt;/strong&gt; controls the number of rows retrieved from the database in one query execution (or one "fetch" from the database cursor).&lt;/li&gt;
&lt;li&gt;It is a performance optimization that helps reduce the number of database round-trips, especially for large datasets.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Relationship Between &lt;code&gt;fetchSize&lt;/code&gt; and &lt;code&gt;chunk()&lt;/code&gt; Size
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If &lt;code&gt;chunk()&lt;/code&gt; size &amp;gt; &lt;code&gt;fetchSize&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Batch will fetch data from the database in smaller batches (based on the &lt;code&gt;fetchSize&lt;/code&gt;) but will still process and commit data in larger chunks.&lt;/li&gt;
&lt;li&gt;For example, if &lt;code&gt;fetchSize = 100&lt;/code&gt; and &lt;code&gt;chunk() = 200&lt;/code&gt;, Spring Batch will first fetch 100 records, then another 100, and process all 200 records in a single chunk before committing.&lt;/li&gt;
&lt;li&gt;There will be &lt;strong&gt;more database round-trips&lt;/strong&gt; compared to a scenario where &lt;code&gt;fetchSize&lt;/code&gt; equals or exceeds &lt;code&gt;chunk()&lt;/code&gt; size.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;If &lt;code&gt;fetchSize &amp;gt; chunk()&lt;/code&gt; size:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Batch will fetch more records than it needs for one chunk, but it will only process the chunk size before committing the transaction.&lt;/li&gt;
&lt;li&gt;For example, if &lt;code&gt;fetchSize = 500&lt;/code&gt; and &lt;code&gt;chunk() = 200&lt;/code&gt;, Spring Batch will fetch 500 records from the database but only process 200 before committing. The remaining 300 will stay in memory for the next chunks.&lt;/li&gt;
&lt;li&gt;This can be more efficient in terms of reducing database round-trips but may consume more memory because the remaining records will be kept in memory until processed.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ideal Configuration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Match &lt;code&gt;chunk()&lt;/code&gt; size and &lt;code&gt;fetchSize&lt;/code&gt; if possible&lt;/strong&gt;: This ensures that Spring Batch fetches exactly the number of records needed for each chunk, minimizing round-trips while avoiding excessive memory usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adjust based on database and memory constraints&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;If your database can handle large fetch sizes without performance degradation, you can set a higher &lt;code&gt;fetchSize&lt;/code&gt; than &lt;code&gt;chunk()&lt;/code&gt; size.&lt;/li&gt;
&lt;li&gt;If memory consumption is a concern, setting &lt;code&gt;fetchSize&lt;/code&gt; equal to or lower than &lt;code&gt;chunk()&lt;/code&gt; size ensures that only the necessary records are held in memory at any time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Scenarios
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chunk Size &amp;gt; Fetch Size Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;   &lt;span class="n"&gt;stepBuilderFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"userEmailStep"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
       &lt;span class="o"&gt;.&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Email&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// Process 500 records per chunk (per transaction)&lt;/span&gt;
       &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;reader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userReader&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;  &lt;span class="c1"&gt;// Fetch 200 records at a time from the database&lt;/span&gt;
       &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;processor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;emailProcessor&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
       &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;writer&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;emailWriter&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
       &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Fetches 200 records from the database.&lt;/li&gt;
&lt;li&gt;Processes the first 200, then fetches another 200, and so on until 500 records are processed in the current chunk.&lt;/li&gt;
&lt;li&gt;The transaction is committed after processing the chunk of 500 records.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fetch Size &amp;gt; Chunk Size Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;   &lt;span class="nc"&gt;JdbcPagingItemReader&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JdbcPagingItemReader&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
   &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setFetchSize&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Fetch 1000 records from the database&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Fetches 1000 records from the database.&lt;/li&gt;
&lt;li&gt;Processes 500 records at a time (assuming &lt;code&gt;chunk(500)&lt;/code&gt;), and the remaining 500 records are stored in memory for the next chunk.&lt;/li&gt;
&lt;li&gt;This reduces the number of database fetches but increases memory usage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;If &lt;code&gt;chunk()&lt;/code&gt; size is larger than &lt;code&gt;fetchSize&lt;/code&gt;&lt;/strong&gt;, it leads to multiple database fetches to process one chunk.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If &lt;code&gt;fetchSize&lt;/code&gt; is larger than &lt;code&gt;chunk()&lt;/code&gt; size&lt;/strong&gt;, the fetched data will stay in memory until fully processed, reducing database fetches but consuming more memory.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>springbatch</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SelectPaginated: Handle Millions of Options Quickly and Efficiently.</title>
      <dc:creator>Shaogat Alam</dc:creator>
      <pubDate>Mon, 08 Jul 2024 11:41:52 +0000</pubDate>
      <link>https://dev.to/shaogat_alam_1e055e90254d/selectpaginated-handle-millions-of-options-quickly-and-efficiently-49fa</link>
      <guid>https://dev.to/shaogat_alam_1e055e90254d/selectpaginated-handle-millions-of-options-quickly-and-efficiently-49fa</guid>
      <description>&lt;p&gt;Hello everyone,&lt;/p&gt;

&lt;p&gt;I'd like to introduce SelectPaginated, a paginated select component for React that can handle large datasets and provide API call and pagination functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The key features of SelectPaginated include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Large Dataset Handling:&lt;/strong&gt; By fetching data in small, manageable chunks and utilizing local storage to cache the fetched data, SelectPaginated effectively handles large datasets without compromising performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Call Integration:&lt;/strong&gt; The component seamlessly integrates API calls, allowing you to fetch data from external sources and present it to your users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pagination:&lt;/strong&gt; SelectPaginated incorporates pagination functionality, enabling your users to navigate through large datasets with ease.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Local Storage Support:&lt;/strong&gt; The component uses the browser's local storage to persist the fetched data, reducing the need for repeated API calls and improving the overall user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Data Support:&lt;/strong&gt; SelectPaginated also supports the use of static data, providing flexibility in the way you handle your application's data requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  To install the select-paginated package, you can use the following command:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;npm i select-paginated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  npmjs - &lt;a href="https://www.npmjs.com/package/select-paginated?activeTab=readme" rel="noopener noreferrer"&gt;select-paginated&lt;/a&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import SelectPaginated from 'select-paginated';

function Test() {
    const options = [
        { id: 1, name: 'Option 1', description: 'This is the first option' },
        { id: 2, name: 'Option 2', description: 'This is the second option' }
    ];

  return (
    &amp;lt;&amp;gt;
        &amp;lt;SelectPaginated 
          // Provide `options` prop when `api` prop is not being used
          options={options} 

          // Provide `api` prop when `options` prop is not being used
          api={{
                resourceUrl: "https://jsonplaceholder.typicode.com/comments",
                pageParamKey: "_page", 
                limitParamKey: "_limit",
                // Final endpoint: "https://jsonplaceholder.typicode.com/comments?_page=1&amp;amp;_limit=50"
            }}
            displayKey="name"
            pageSize={50}
            isLinearArray={false}
            onSelect={(selectedItems) =&amp;gt; {
                console.log('selected items :: ', JSON.stringify(selectedItems));
            }}
            onRemove={(removedItem) =&amp;gt; {
                console.log('Removed items :: ', JSON.stringify(removedItem));
            }}
            multiSelect={true}
            searchPlaceholder="Search..."
            localStorageKey="SelectFetchedData"
        /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

export default Test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Props
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;options&lt;/em&gt;&lt;/strong&gt;(array,required when &lt;code&gt;api&lt;/code&gt; prop is not provided )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Description: An array of pre-defined options to be used instead of fetching data from an API.This can be particularly useful for small dataset, static datasets or for data that is already available on the client side.&lt;/li&gt;
&lt;li&gt;  Example : 

&lt;ul&gt;
&lt;li&gt;  Simple linear array - [ "Item 1", "Item 2",  "Item 3", // ...more items],&lt;/li&gt;
&lt;li&gt;  Array of objects - [ { id: 1, name: "Item 1" },  { id: 2, name: "Item 2" }, // ...more items ]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;pageSize&lt;/em&gt;&lt;/strong&gt;(number,default:50) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The number of items to show and fetch(in-case of fetching data) per page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;isLinearArray&lt;/em&gt;&lt;/strong&gt;(boolean,default:false) : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set {true} when :

&lt;ul&gt;
&lt;li&gt;The fetched data or value of &lt;code&gt;options&lt;/code&gt; prop is a simple linear array of primitive values (e.g., strings, numbers).&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;displayKey&lt;/code&gt; is needed.&lt;/li&gt;
&lt;li&gt;Example: ["item1", "item2", "item3"]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Set {false} when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The fetched data or value of &lt;code&gt;options&lt;/code&gt; prop is an array of objects.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;displayKey&lt;/code&gt; must be specified to indicate which property to display.
c. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"id labore ex et quam laborum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Eliseo@gardner.biz"&lt;/span&gt;&lt;span class="p"&gt;,},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"quo vero reiciendis velit similique earum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Jayne_Kuhic@sydney.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;In this case, set &lt;code&gt;displayKey&lt;/code&gt; to the property you want to display, e.g., "email".&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;displayKey&lt;/em&gt;&lt;/strong&gt;(string,default:'name',required only when &lt;code&gt;isLinearArray&lt;/code&gt; is false) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Description : Specifies the property of the objects in the array to be displayed.&lt;br&gt;
For instance, consider the following response from an API:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"id labore ex et quam laborum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Eliseo@gardner.biz"&lt;/span&gt;&lt;span class="p"&gt;,},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"quo vero reiciendis velit similique earum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Jayne_Kuhic@sydney.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;


&lt;ul&gt;
&lt;li&gt;To display the "email" field, set &lt;code&gt;displayKey&lt;/code&gt; to "email".&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;api&lt;/em&gt;&lt;/strong&gt;(object,required when &lt;code&gt;options&lt;/code&gt; prop is not provided) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Properties : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;resourceUrl&lt;/strong&gt; (string, required):

&lt;ul&gt;
&lt;li&gt;The URL from which data will be fetched.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;  &lt;strong&gt;pageParamKey&lt;/strong&gt; (string, optional, default: "_page") :

&lt;ul&gt;
&lt;li&gt;This is the query parameter key used by your backend API to specify the page number. It should match what your backend expects for pagination.Common defaults include "page", "pageNumber", "p".&lt;/li&gt;
&lt;li&gt;Example : If pageParamKey is set to "page", the API request URL might include ?page=1, ?page=2, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;  &lt;strong&gt;limitParamKey&lt;/strong&gt; (string, optional, default: "_limit") :

&lt;ul&gt;
&lt;li&gt;This is the query parameter key used by your backend API to specify the number of items per page. Similar to pageParamKey, 
it should align with your backend's pagination configuration. Common defaults include "limit", "pageSize", "size".&lt;/li&gt;
&lt;li&gt;Example: If limitParamKey is set to "size", the API request URL might include ?size=10, ?size=20, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;onSelect&lt;/em&gt;&lt;/strong&gt; (function, optional) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A callback function invoked when items are selected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;onRemove&lt;/em&gt;&lt;/strong&gt; (function, optional) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A callback function invoked when items are removed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;multiSelect&lt;/em&gt;&lt;/strong&gt; (boolean, optional, default: true) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Enables or disables multi-selection mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;searchPlaceholder&lt;/em&gt;&lt;/strong&gt; (string, optional, default: "Search...") :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Placeholder text for the search input field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;localStorageKey&lt;/em&gt;&lt;/strong&gt; (string, optional, default: "SelectFetchedData") :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The unique key used to store data in local storage for persistence.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>SelectPaginated: Handle Millions of Options Quickly and Efficiently.</title>
      <dc:creator>Shaogat Alam</dc:creator>
      <pubDate>Fri, 28 Jun 2024 15:10:21 +0000</pubDate>
      <link>https://dev.to/shaogat_alam_1e055e90254d/introducing-selectpaginated-a-paginated-select-component-for-react-68b</link>
      <guid>https://dev.to/shaogat_alam_1e055e90254d/introducing-selectpaginated-a-paginated-select-component-for-react-68b</guid>
      <description>&lt;p&gt;Hello everyone,&lt;/p&gt;

&lt;p&gt;I'd like to introduce SelectPaginated, a paginated select component for React that can handle large datasets and provide API call and pagination functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The key features of SelectPaginated include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Large Dataset Handling:&lt;/strong&gt; By fetching data in small, manageable chunks and utilizing local storage to cache the fetched data, SelectPaginated effectively handles large datasets without compromising performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Call Integration:&lt;/strong&gt; The component seamlessly integrates API calls, allowing you to fetch data from external sources and present it to your users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pagination:&lt;/strong&gt; SelectPaginated incorporates pagination functionality, enabling your users to navigate through large datasets with ease.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Local Storage Support:&lt;/strong&gt; The component uses the browser's local storage to persist the fetched data, reducing the need for repeated API calls and improving the overall user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Data Support:&lt;/strong&gt; SelectPaginated also supports the use of static data, providing flexibility in the way you handle your application's data requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  To install the select-paginated package, you can use the following command:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;npm i select-paginated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  npmjs - &lt;a href="https://www.npmjs.com/package/select-paginated?activeTab=readme" rel="noopener noreferrer"&gt;select-paginated&lt;/a&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import SelectPaginated from 'select-paginated';

function Test() {
    const options = [
        { id: 1, name: 'Option 1', description: 'This is the first option' },
        { id: 2, name: 'Option 2', description: 'This is the second option' }
    ];

  return (
    &amp;lt;&amp;gt;
        &amp;lt;SelectPaginated 
          // Provide `options` prop when `api` prop is not being used
          options={options} 

          // Provide `api` prop when `options` prop is not being used
          api={{
                resourceUrl: "https://jsonplaceholder.typicode.com/comments",
                pageParamKey: "_page", 
                limitParamKey: "_limit",
                // Final endpoint: "https://jsonplaceholder.typicode.com/comments?_page=1&amp;amp;_limit=50"
            }}
            displayKey="name"
            pageSize={50}
            isLinearArray={false}
            onSelect={(selectedItems) =&amp;gt; {
                console.log('selected items :: ', JSON.stringify(selectedItems));
            }}
            onRemove={(removedItem) =&amp;gt; {
                console.log('Removed items :: ', JSON.stringify(removedItem));
            }}
            multiSelect={true}
            searchPlaceholder="Search..."
            localStorageKey="SelectFetchedData"
        /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

export default Test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Props
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;options&lt;/em&gt;&lt;/strong&gt;(array,required when &lt;code&gt;api&lt;/code&gt; prop is not provided )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Description: An array of pre-defined options to be used instead of fetching data from an API.This can be particularly useful for small dataset, static datasets or for data that is already available on the client side.&lt;/li&gt;
&lt;li&gt;  Example : 

&lt;ul&gt;
&lt;li&gt;  Simple linear array - [ "Item 1", "Item 2",  "Item 3", // ...more items],&lt;/li&gt;
&lt;li&gt;  Array of objects - [ { id: 1, name: "Item 1" },  { id: 2, name: "Item 2" }, // ...more items ]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;pageSize&lt;/em&gt;&lt;/strong&gt;(number,default:50) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The number of items to show and fetch(in-case of fetching data) per page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;isLinearArray&lt;/em&gt;&lt;/strong&gt;(boolean,default:false) : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set {true} when :

&lt;ul&gt;
&lt;li&gt;The fetched data or value of &lt;code&gt;options&lt;/code&gt; prop is a simple linear array of primitive values (e.g., strings, numbers).&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;displayKey&lt;/code&gt; is needed.&lt;/li&gt;
&lt;li&gt;Example: ["item1", "item2", "item3"]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Set {false} when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The fetched data or value of &lt;code&gt;options&lt;/code&gt; prop is an array of objects.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;displayKey&lt;/code&gt; must be specified to indicate which property to display.
c. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"id labore ex et quam laborum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Eliseo@gardner.biz"&lt;/span&gt;&lt;span class="p"&gt;,},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"quo vero reiciendis velit similique earum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Jayne_Kuhic@sydney.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;In this case, set &lt;code&gt;displayKey&lt;/code&gt; to the property you want to display, e.g., "email".&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;displayKey&lt;/em&gt;&lt;/strong&gt;(string,default:'name',required only when &lt;code&gt;isLinearArray&lt;/code&gt; is false) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Description : Specifies the property of the objects in the array to be displayed.&lt;br&gt;
For instance, consider the following response from an API:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"id labore ex et quam laborum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Eliseo@gardner.biz"&lt;/span&gt;&lt;span class="p"&gt;,},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"quo vero reiciendis velit similique earum"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Jayne_Kuhic@sydney.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;


&lt;ul&gt;
&lt;li&gt;To display the "email" field, set &lt;code&gt;displayKey&lt;/code&gt; to "email".&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;api&lt;/em&gt;&lt;/strong&gt;(object,required when &lt;code&gt;options&lt;/code&gt; prop is not provided) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Properties : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;resourceUrl&lt;/strong&gt; (string, required):

&lt;ul&gt;
&lt;li&gt;The URL from which data will be fetched.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;  &lt;strong&gt;pageParamKey&lt;/strong&gt; (string, optional, default: "_page") :

&lt;ul&gt;
&lt;li&gt;This is the query parameter key used by your backend API to specify the page number. It should match what your backend expects for pagination.Common defaults include "page", "pageNumber", "p".&lt;/li&gt;
&lt;li&gt;Example : If pageParamKey is set to "page", the API request URL might include ?page=1, ?page=2, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;  &lt;strong&gt;limitParamKey&lt;/strong&gt; (string, optional, default: "_limit") :

&lt;ul&gt;
&lt;li&gt;This is the query parameter key used by your backend API to specify the number of items per page. Similar to pageParamKey, 
it should align with your backend's pagination configuration. Common defaults include "limit", "pageSize", "size".&lt;/li&gt;
&lt;li&gt;Example: If limitParamKey is set to "size", the API request URL might include ?size=10, ?size=20, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;onSelect&lt;/em&gt;&lt;/strong&gt; (function, optional) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A callback function invoked when items are selected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;onRemove&lt;/em&gt;&lt;/strong&gt; (function, optional) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A callback function invoked when items are removed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;multiSelect&lt;/em&gt;&lt;/strong&gt; (boolean, optional, default: true) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Enables or disables multi-selection mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;searchPlaceholder&lt;/em&gt;&lt;/strong&gt; (string, optional, default: "Search...") :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Placeholder text for the search input field.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;localStorageKey&lt;/em&gt;&lt;/strong&gt; (string, optional, default: "SelectFetchedData") :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The unique key used to store data in local storage for persistence.&lt;/li&gt;
&lt;/ul&gt;

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