<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Losalini Rokocakau - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Losalini Rokocakau - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 12 May 2026 20:31:02 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/chelmerrox/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Manually Deploy a React and TypeScript Project on Netlify ]]>
                </title>
                <description>
                    <![CDATA[ In this tutorial, I'll teach you how to manually deploy a React and TypeScript project with Vite on Netlify. I will show you a few quick and simple steps to get live versions of your projects up and running. To follow along with this tutorial, there ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/manually-deploy-a-react-and-typescript-project-on-netlify/</link>
                <guid isPermaLink="false">66ba5226e727ef4561965aa7</guid>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Netlify ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ TypeScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Losalini Rokocakau ]]>
                </dc:creator>
                <pubDate>Fri, 12 Apr 2024 18:02:59 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/cover-image-4.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this tutorial, I'll teach you how to manually deploy a React and TypeScript project with Vite on Netlify. I will show you a few quick and simple steps to get live versions of your projects up and running.</p>
<p>To follow along with this tutorial, there are a few prerequisites:</p>
<ol>
<li>An existing React and TypeScript project with Vite that you want to deploy.</li>
<li>Visual Studio Code (VSCode) editor or any other code editor such as Sublime.</li>
<li>Optionally, you can just use a command line/terminal instead of your code editor's built-in terminal.</li>
<li>An existing Netlify account that you've already logged into.</li>
</ol>
<p>Let's go ahead with our deployment!</p>
<h3 id="heading-what-to-expect">What to expect</h3>
<p>You will deploy your project manually on Netlify, rename your site on the platform, and be able to have a live version of your project.</p>
<h2 id="heading-how-to-deploy-your-react-and-typescript-project">How to Deploy Your React and TypeScript Project</h2>
<h3 id="heading-1-open-up-your-existing-project-on-vscode">1. Open up your existing project on VSCode</h3>
<p>Open up your project in the code editor of your choice.</p>
<h3 id="heading-2-build-the-project">2. Build the project</h3>
<p>Open the terminal in VSCode and use the code below to build your project:</p>
<pre><code>npm run build
</code></pre><p>This should generate a <em>dist</em> folder in your root directory where your projects' minified version is created and stored.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-2-0.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 2.0</strong> Running the project in the terminal which creates the dist folder in the project structure.</em></p>
<h3 id="heading-3-drag-and-drop-your-dist-folder-in-netlify">3. Drag and Drop your Dist Folder in Netlify</h3>
<p>On Netlify under Team Overview, click on the Add New Site button. It should have three options:</p>
<ol>
<li>Import an existing project</li>
<li>Start from a template</li>
<li>Deploy manually</li>
</ol>
<p>Select the third choice to deploy manually.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-3-0.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 3.0</strong> Clicking on the Add new site button shows the three options to choose from. Select "Deploy Manually".</em></p>
<p>It should lead you to the page as seen in the below image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-3-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 3.1</strong> Drag &amp; drop view when choosing to deploy manually.</em></p>
<p>Click on the page and navigate into your project's file path.</p>
<p>Upload the dist folder that was previously generated in your project onto Netlify.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-3-2.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 3.2</strong> Navigating into the project's folder &amp; uploading the dist folder onto Netlify.</em></p>
<p>It will take a few seconds or minutes to get your project deployed.</p>
<p>Once deployment is successful, you will see a page similar to the one below. By default, it gives a randomly generated subdomain name to your site's URL. For example, in my case, it is <em>delightful-pie-bba293.</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-3-3.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 3.3</strong> Deployment is successful.</em></p>
<p>Your site's name is the subdomain of Netlify's domain.</p>
<pre><code>https:<span class="hljs-comment">//&lt;your-site-name&gt;.netlify.app</span>
</code></pre><h3 id="heading-4-rename-your-site">4. Rename your site</h3>
<p>Click on the Site Configuration that is on the lefthand sidebar.</p>
<p>In the Site Information under Site Details, click on the Change Site Name button.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-4-0.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 4.0</strong> Viewing the Site Details under the Site Configuration.</em></p>
<p>This should give you a pop-up to change your site's name.</p>
<p>Change the name of your site to whatever you like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-4-1-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 4.1</strong> Changing the name of your site.</em></p>
<p>Head back to the Site Overview where you can find the URL of your site. Your site's URL is found right underneath your project's name.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/figure-4-2.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 4.2</strong> Site Overview where you can find your site's URL.</em></p>
<p>Click on the URL to view your site!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/fig-4-3-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 4.3</strong> Viewing my site from the newly created URL.</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Now, you have live versions of your projects and you're able to deploy them manually on Netlify. </p>
<p>There are additional steps to take in order to add a custom domain but we're not covering that in this tutorial. </p>
<p>This also makes it easier to reference your projects in the meantime on your résumés, portfolio site, or anywhere else.</p>
<p>Thanks for powering through this article and happy coding! 🩷</p>
<h3 id="heading-additional-resources">📝Additional Resources:</h3>
<ol>
<li>This article is a summarized version of this <a target="_blank" href="https://www.youtube.com/watch?v=7T4w0QJtL-o">video</a>. If you'd prefer to watch and follow along, then that is the video to watch.</li>
<li>There are many other platforms such as <a target="_blank" href="https://www.cloudflare.com/en-gb/">Cloudflare</a>, <a target="_blank" href="https://www.heroku.com/">Heroku</a>, or <a target="_blank" href="https://vercel.com/">Vercel</a> to deploy your projects on. This <a target="_blank" href="https://www.youtube.com/watch?v=gcwQg8-wqQ0">video</a>, for instance, shows you how to deploy your projects onto Vercel.</li>
</ol>
<h3 id="heading-connect-with-me">🔍Connect with me!</h3>
<p>Follow me on <a target="_blank" href="https://twitter.com/chelmerrox">X</a> and <a target="_blank" href="http://www.linkedin.com/in/losalini-rokocakau">LinkedIn</a> if you like my work and want to stay updated for more.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create Tables Using the React-Data-Table-Component Library in React & TypeScript ]]>
                </title>
                <description>
                    <![CDATA[ In this tutorial, I'll teach you how to use the react-data-table-component library in your React projects. You'll learn how to render a table that has features such as pagination, searching/filtering, and sorting.  I'll walk you through each step, fr... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/create-tables-using-the-react-datatable-component-library/</link>
                <guid isPermaLink="false">66ba5222256e9dbeab31aa92</guid>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ TypeScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ user experience ]]>
                    </category>
                
                    <category>
                        <![CDATA[ User Interface ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Losalini Rokocakau ]]>
                </dc:creator>
                <pubDate>Wed, 27 Mar 2024 15:40:38 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/03/cover-image-21.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this tutorial, I'll teach you how to use the <em>react-data-table-component</em> library in your React projects. You'll learn how to render a table that has features such as pagination, searching/filtering, and sorting. </p>
<p>I'll walk you through each step, from setting up a React and TypeScript project with Vite to using the <em>react-data-table-component</em> library to render a table.</p>
<p>To follow along with this tutorial, there are a few prerequisites:</p>
<ol>
<li>A basic understanding of React and TypeScript</li>
<li>Basic knowledge of Bootstrap, which we'll use for styling</li>
<li>For Windows OS users, know how to use the PowerShell terminal (as you'll need an interactive terminal to create the project with Vite)</li>
<li>Node v20.11.1 installed</li>
<li>npm v10.2.4 installed</li>
<li>A code editor such as Visual Studio Code (VS Code) or Atom</li>
</ol>
<p>Let's start creating the project!</p>
<h3 id="heading-what-will-we-build">What will we build</h3>
<p>By the end of this tutorial, you will have built a table that displays a person's ID, name, height, and eye color.</p>
<p>The table will also have a search bar where users can search for a person based on the value of any of the four properties mentioned above.</p>
<p>Each row in the table will be selectable and each column will be sortable when the column header is clicked by a user.</p>
<h2 id="heading-1-create-a-react-and-typescript-project">1. Create a React and TypeScript Project</h2>
<p>In the command line, create the project with the command below:</p>
<pre><code>npm create vite@latest
</code></pre><p>Name the project <code>react-data-table-tutorial</code> .</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/03/fig-1-0-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 1.0</strong> Creating the React &amp; TypeScript project with Vite on PowerShell command line. Naming the project react-data-table-tutorial.</em></p>
<p>Navigate to React with the up and down keys to select React. Choose React as the library you're going to use.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/03/fig-1-1-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 1.1</strong> Selecting React as our framework by navigating to it on the list with up &amp; down arrow keys on the keyboard.</em></p>
<p>Similar to the step above, navigate to TypeScript and choose it as the language to use.</p>
<p>The next step is to change directories into the project's folder. Once you've done that, open the project in your code editor as seen in Figure 1.2 below. I'll be using the VS Code editor in this tutorial.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/03/fig-1-2-2.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 1.2</strong> Changing the folder into the react-data-table-tutorial directory and opening the contents of the folder into a code editor.</em></p>
<h2 id="heading-2-remove-the-default-code-set-by-react">2. Remove the Default Code Set by React</h2>
<p>This step is just to remove any default code and stylings in the files found in the <em>src</em> folder. </p>
<p>First, remove all default styling in the <em>App.css</em> file and replace it with the stylings below.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">background-color</span>: white;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">160px</span> <span class="hljs-number">500px</span>;
}
</code></pre>
<p>Then remove the following from the <em>App.tsx</em> file:</p>
<ul>
<li>the imported statements of the <code>useState</code> hook, <code>reactLogo</code>, and the <code>viteLogo</code><em>.</em></li>
<li>The destructured array and <code>useState</code> hook for the count variable and <code>setCount</code> function.</li>
<li>The returned JSX wrapped within the fragment of the <code>App</code> component.</li>
</ul>
<p>The <code>App</code> component should look like the code-block below after all of those changes:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;&gt;</span><span class="hljs-tag">&lt;/&gt;</span></span>;
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<h2 id="heading-3-install-the-libraries-well-need">3. Install the Libraries We'll Need</h2>
<p>In the project, you will need to install a few libraries:</p>
<ol>
<li><em>styled-components</em> v3.23+</li>
<li><em>react-data-table-component</em> v16.8.0+</li>
<li><em>Bootstrap</em> v5.3.3</li>
</ol>
<p>You will need to install the <em>styled-components</em> library to use with the <em>react-data-table-component</em> library.</p>
<p>In the command line, install all of these by using the commands below:</p>
<pre><code>npm install styled-components
</code></pre><pre><code>npm install react-data-table-components
</code></pre><pre><code>npm install bootstrap@<span class="hljs-number">5.3</span><span class="hljs-number">.3</span>
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2024/03/fig-3-0.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 3.0</strong> Installing the libraries on Visual Studio Code's built-in terminal.</em></p>
<p>The installed libraries are listed under dependencies in the <em>package.json</em> file.</p>
<pre><code class="lang-json">{
   <span class="hljs-comment">// rest of the code in the file</span>
    <span class="hljs-attr">"dependencies"</span>: {
        <span class="hljs-attr">"boostrap"</span>: <span class="hljs-string">"^5.3.3"</span>,
        <span class="hljs-attr">"react"</span>: <span class="hljs-string">"^18.2.0"</span>,
        <span class="hljs-attr">"react-data-table-component"</span>: <span class="hljs-string">"^7.6.2"</span>,
        <span class="hljs-attr">"react-dom"</span>: <span class="hljs-string">"^18.2.0"</span>,
        <span class="hljs-attr">"styled-components"</span>: <span class="hljs-string">"^6.1.8"</span>,
    }
    <span class="hljs-comment">// rest of the code in the file</span>
}
</code></pre>
<h2 id="heading-4-import-bootstrap-in-the-app-component">4. Import Bootstrap in the App Component</h2>
<p>In the <em>App.tsx</em> file, import the Bootstrap library at the top of the file.</p>
<p>This will allow us to use Bootstrap stylings throughout the project.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> <span class="hljs-string">"./App.css"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"bootstrap/dist/js/bootstrap.bundle.min.js"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>)</span>{
   <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;&gt;</span><span class="hljs-tag">&lt;/&gt;</span></span>;
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<h2 id="heading-5-create-a-table-component">5. Create a Table Component</h2>
<p>In the <em>src</em> folder, create a sub-directory and name it <em>components</em>. By convention, this is to hold all of the components of the project.</p>
<p>In the <em>components</em> folder, create a file called <em>Table.tsx</em>. This is for our <code>Table</code> component.</p>
<p>Create a function component called <code>Table</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/03/fig-4-0.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 5.0</strong> Create the Table component in the components sub-directory within the src folder.</em></p>
<h2 id="heading-6-import-the-react-data-table-component-library-to-start-using-it">6. Import the react-data-table-component Library to Start Using it</h2>
<p>Import the <em>react-data-table-component</em> library into the <code>Table</code> component.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> DataTable <span class="hljs-keyword">from</span> <span class="hljs-string">"react-data-table-component"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Table</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;&gt;</span><span class="hljs-tag">&lt;/&gt;</span></span>;
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Table;
</code></pre>
<h2 id="heading-7-create-the-table-in-the-table-component">7. Create the Table in the Table Component</h2>
<p>Create a <code>&lt;div&gt;</code> container within the fragment and add Bootstrap styling of <code>container</code> and <code>my-5</code> to place the table in the center of the page.</p>
<p>Add the <code>DataTable</code> component as the child of the <code>&lt;div&gt;</code> container.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> DataTable <span class="hljs-keyword">from</span> <span class="hljs-string">'react-data-table-component'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Table</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"container my-5"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">DataTable</span> /&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/&gt;</span></span>
    );
}
</code></pre>
<p>Pass the columns and rows of the table as props to the <code>DataTable</code> component.</p>
<p>The column headers of the table are objects that will be stored in an array. The rows of the table will also be stored in a similar way. The array of objects for both will have these structures:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> columns = [
    {
        <span class="hljs-attr">name</span>: <span class="hljs-string">"ID"</span>,
        <span class="hljs-attr">selector</span>: <span class="hljs-function"><span class="hljs-params">row</span> =&gt;</span> row.id
    },
    {
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Full Name"</span>,
        <span class="hljs-attr">selector</span>: <span class="hljs-function"><span class="hljs-params">row</span> =&gt;</span> row.fullName
    },
    {
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Height"</span>,
        <span class="hljs-attr">selector</span>: <span class="hljs-function"><span class="hljs-params">row</span> =&gt;</span> row.height
    },
    {
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Weight"</span>,
        <span class="hljs-attr">selector</span>: <span class="hljs-function"><span class="hljs-params">row</span> =&gt;</span> row.weight
    },
];
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> rows = [
    {
        <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
        <span class="hljs-attr">fullName</span>: <span class="hljs-string">"John Doe"</span>,
        <span class="hljs-attr">height</span>: <span class="hljs-string">"1.75m"</span>,
        <span class="hljs-attr">weight</span>: <span class="hljs-string">"89kg"</span>,
    },
    {
        <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>,
        <span class="hljs-attr">fullName</span>: <span class="hljs-string">"Jane Doe"</span>,
        <span class="hljs-attr">height</span>: <span class="hljs-string">"1.64m"</span>,
        <span class="hljs-attr">weight</span>: <span class="hljs-string">"55kg"</span>,
    },
    {
        <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>,
        <span class="hljs-attr">fullName</span>: <span class="hljs-string">"Sheera Maine"</span>,
        <span class="hljs-attr">height</span>: <span class="hljs-string">"1.69m"</span>,
        <span class="hljs-attr">weight</span>: <span class="hljs-string">"74kg"</span>,
    },
];
</code></pre>
<p>These constants are then passed into the <code>DataTable</code> component as such:</p>
<pre><code class="lang-jsx">&lt;DataTable columns={columns} data={rows} /&gt;
</code></pre>
<p>Create a <code>columns</code> constant that is an array of objects that has four columns headers for <code>personID</code>, <code>fullName</code>, <code>height</code>, and <code>eyeColor</code>.</p>
<p>Create a <code>rows</code> constant that is an array of objects that has 15 objects which is equivalent to data for 15 people.</p>
<p>Pass the two constants into their respective props in the <code>DataTable</code> component as seen in the next code-block.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Table</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">const</span> columns = [
        {
            <span class="hljs-attr">name</span>: <span class="hljs-string">"ID"</span>,
            <span class="hljs-attr">selector</span>: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.personID,
        },
        {
            <span class="hljs-attr">name</span>: <span class="hljs-string">"Full Name"</span>,
            <span class="hljs-attr">selector</span>: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.fullName,
        },
        {
            <span class="hljs-attr">name</span>: <span class="hljs-string">"Height"</span>,
            <span class="hljs-attr">selector</span>: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.height,
        },
        {
            <span class="hljs-attr">name</span>: <span class="hljs-string">"eyeColor"</span>,
            <span class="hljs-attr">selector</span>: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.eyeColor,
        },
    ];

    <span class="hljs-keyword">const</span> rows = [
        {
           <span class="hljs-attr">personID</span>: <span class="hljs-number">1</span>,
           <span class="hljs-attr">fullName</span>: <span class="hljs-string">"Kate Shein"</span>,
           <span class="hljs-attr">height</span>: <span class="hljs-string">"1.79m"</span>,
           <span class="hljs-attr">eyeColor</span>: <span class="hljs-string">"blue"</span>,
        },
        <span class="hljs-comment">//....remaining objects for the 2nd to 14th person</span>
        {
           <span class="hljs-attr">personID</span>: <span class="hljs-number">15</span>,
           <span class="hljs-attr">fullName</span>: <span class="hljs-string">"Isabella Thompson"</span>,
           <span class="hljs-attr">height</span>: <span class="hljs-string">"1.79m"</span>,
           <span class="hljs-attr">eyeColor</span>: <span class="hljs-string">"blue"</span>,
        },
    ];
}
</code></pre>
<p>You will also add the <code>fixedHeader</code> prop to the <code>DataTable</code> component to keep the column header fixed when a user scrolls down the table that has more than 10 records.</p>
<p>Give the table a title by passing the <code>title</code> prop to the component and its value is whatever you would like to call your table.</p>
<pre><code class="lang-javascript">&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"container"</span>&gt;
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">DataTable</span> 
        <span class="hljs-attr">columns</span>=<span class="hljs-string">{columns}</span> 
        <span class="hljs-attr">data</span>=<span class="hljs-string">{rows}</span> 
        <span class="hljs-attr">fixedHeader</span>
        <span class="hljs-attr">title</span>=<span class="hljs-string">"React-Data-Table-Component Tutorial."</span>
     /&gt;</span></span>
&lt;/div&gt;
</code></pre>
<p>Back in the <code>App</code> component, import the <code>Table</code> component and place it within the fragment.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> <span class="hljs-string">"./App.css"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"bootstrap/dist/js/bootstrap.bundle.min.js"</span>;
<span class="hljs-keyword">import</span> Table <span class="hljs-keyword">from</span> <span class="hljs-string">"./components/Table"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
           <span class="hljs-tag">&lt;<span class="hljs-name">Table</span> /&gt;</span>
        <span class="hljs-tag">&lt;/&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<h2 id="heading-8-add-pagination-and-sorting-and-make-each-row-selectable">8. Add Pagination and Sorting, and Make Each Row Selectable</h2>
<h3 id="heading-pagination-and-selectablerows">Pagination and <code>selectableRows</code></h3>
<p>Add the <code>pagination</code> and <code>selectableRows</code> props to the <code>DataTable</code> component.</p>
<p>By default, the first page has the first 10 records. If there needs to be API calls from the server side for custom pagination, then you can use the <code>paginationServer</code> property along with the <code>paginationTotalRows</code><em>,</em> <code>onChangeRowsPerPage</code> and <code>onChangePage</code> properties which work in conjunction with a few other things.</p>
<p>But for now, let's stick with the <code>pagination</code> property.</p>
<pre><code class="lang-jsx"><span class="hljs-comment">//...rest of the code in the function component</span>
&lt;div className=<span class="hljs-string">"container d-flex justify-content-center my-5"</span>&gt;
   <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">DataTable</span>
        <span class="hljs-attr">columns</span>=<span class="hljs-string">{columns}</span>
        <span class="hljs-attr">data</span>=<span class="hljs-string">{rows}</span>
        <span class="hljs-attr">fixedHeader</span>
        <span class="hljs-attr">title</span>=<span class="hljs-string">"React-Data-Table-Component Tutorial"</span>
        <span class="hljs-attr">pagination</span>
        <span class="hljs-attr">selectableRows</span>
    /&gt;</span></span>
&lt;/div&gt;
<span class="hljs-comment">//...rest of the code in the function component</span>
</code></pre>
<h3 id="heading-sorting">Sorting</h3>
<p>In the <code>DataTable</code> component, add the <code>sortable</code> property to each object in the <code>columns</code> constant. Give it a boolean value of <code>true</code> so that sorting is applied to each column when a user clicks on the column headers.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//...rest of the code in the function component</span>
<span class="hljs-keyword">const</span> columns = [
    {
        name: <span class="hljs-string">'ID'</span>,
        selector: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.personID,
        sortable: <span class="hljs-literal">true</span>,
    },
    {
        name: <span class="hljs-string">'Full Name'</span>,
        selector: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.fullName,
        sortable: <span class="hljs-literal">true</span>,
    },
    {
        name: <span class="hljs-string">'Height'</span>,
        selector: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.height,
        sortable: <span class="hljs-literal">true</span>,
    },
    {
        name: <span class="hljs-string">'Eye Color'</span>,
        selector: <span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> row.eyeColor,
        sortable: <span class="hljs-literal">true</span>,
    },
];
<span class="hljs-comment">//...rest of the code in the function component</span>
</code></pre>
<h2 id="heading-9-add-searching-and-filtering">9. Add Searching and Filtering</h2>
<p>Add a <code>&lt;div&gt;</code> container above the <code>DataTable</code> component in the returned JSX. Also add the bootstrap <code>input-group</code> class to the <code>&lt;div&gt;</code>.</p>
<p>The child element of this new container will be the <code>&lt;input /&gt;</code> of type <code>search</code> and we'll use Bootstraps' stylings for it. Use the code below:</p>
<pre><code class="lang-jsx">&lt;input
    type=<span class="hljs-string">"search"</span>
    className=<span class="hljs-string">"form-control-sm border ps-3"</span>
    placeholder=<span class="hljs-string">"Search"</span>
/&gt;
</code></pre>
<p>An optional step is to add a search icon or use <a target="_blank" href="https://getbootstrap.com/docs/5.3/forms/input-group/">Bootstraps' default styling</a> for a search bar. However, we'll leave it out for now so we can focus solely on the searching functionality.</p>
<p>Now, let's import the <code>useState</code> hook into the <em>Table.tsx</em> file.</p>
<p>Use the hook and pass in the <code>rows</code> constant as the default value of our state variable. Within the destructured array will be our state variable called <code>data</code> and the setter function called <code>setData</code>.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> [data, setData] = useState(rows);
</code></pre>
<p>Create a function called <code>handleSearch</code> that will be called when the <code>onChange</code> event listener is used on the search bar. </p>
<p>Pass in the event object, <code>e</code>, as its argument. Using type annotation, set the type of the event object to <code>React.ChangeEvent&lt;HTMLInputElement&gt;</code>.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> handleSearch = <span class="hljs-function">(<span class="hljs-params">e: React.ChangeEvent&lt;HTMLInputElement&gt;</span>) =&gt;</span> {
   <span class="hljs-comment">// the rest of the code will be defined in here</span>
};
</code></pre>
<p>Declare 5 variables of Boolean type as seen below:</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> handleSearch = <span class="hljs-function">(<span class="hljs-params">e: React.ChangeEvent&lt;HTMLInputElement&gt;</span>) =&gt;</span> {
   <span class="hljs-keyword">let</span> searchValue: <span class="hljs-built_in">Boolean</span>;
   <span class="hljs-keyword">let</span> personIDValue: <span class="hljs-built_in">Boolean</span>;
   <span class="hljs-keyword">let</span> fullNameValue: <span class="hljs-built_in">Boolean</span>;
   <span class="hljs-keyword">let</span> heightValue: <span class="hljs-built_in">Boolean</span>;
   <span class="hljs-keyword">let</span> eyeColorValue: <span class="hljs-built_in">Boolean</span>;
};
</code></pre>
<p>Declare a new local constant called <code>newRows</code><em>.</em> In this constant, filter out and return the rows/data in the <em>rows</em> constant where the search input's value is the same as the value of the rows' <code>fullName</code> or <code>height</code> or <code>eyeColor</code> property.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> newRows = rows.filter(<span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> {
      personIDValue = row.personID
        .toString()
        .toLowerCase()
        .includes(e.target.value.toLowerCase());
      fullNameValue = row.fullName
        .toLowerCase()
        .includes(e.target.value.toLowerCase());
      heightValue = row.height
        .toLowerCase()
        .includes(e.target.value.toLowerCase());
      eyeColorValue = row.eyeColor
        .toLowerCase()
        .includes(e.target.value.toLowerCase());

      <span class="hljs-keyword">if</span> (personIDValue) {
        searchValue = personIDValue;
      } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (fullNameValue) {
        searchValue = fullNameValue;
      } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (heightValue) {
        searchValue = heightValue;
      } <span class="hljs-keyword">else</span> {
        searchValue = eyeColorValue;
      }

      <span class="hljs-keyword">return</span> searchValue;
});
</code></pre>
<p>Pass <code>newRows</code> into the setter function, <code>setData</code><em>.</em></p>
<pre><code class="lang-typescript">setData(newRows);
</code></pre>
<pre><code class="lang-typescript"><span class="hljs-comment">// definition of the columns constant</span>

<span class="hljs-comment">// definition of the rows constant</span>

<span class="hljs-keyword">const</span> [data, setData] = useState(rows);

<span class="hljs-comment">// Handle Search</span>
<span class="hljs-keyword">const</span> handleSearch = <span class="hljs-function">(<span class="hljs-params">e: React.ChangeEvent&lt;HTMLInputElement&gt;</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> searchValue: <span class="hljs-built_in">Boolean</span>;
    <span class="hljs-keyword">let</span> personIDValue: <span class="hljs-built_in">Boolean</span>;
    <span class="hljs-keyword">let</span> fullNameValue: <span class="hljs-built_in">Boolean</span>;
    <span class="hljs-keyword">let</span> heightValue: <span class="hljs-built_in">Boolean</span>;
    <span class="hljs-keyword">let</span> eyeColorValue: <span class="hljs-built_in">Boolean</span>;

    <span class="hljs-keyword">const</span> newRows = rows.filter(<span class="hljs-function">(<span class="hljs-params">row</span>) =&gt;</span> {
      personIDValue = row.personID
        .toString()
        .toLowerCase()
        .includes(e.target.value.toLowerCase());
      fullNameValue = row.fullName
        .toLowerCase()
        .includes(e.target.value.toLowerCase());
      heightValue = row.height
        .toLowerCase()
        .includes(e.target.value.toLowerCase());
      eyeColorValue = row.eyeColor
        .toLowerCase()
        .includes(e.target.value.toLowerCase());

      <span class="hljs-keyword">if</span> (personIDValue) {
        searchValue = personIDValue;
      } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (fullNameValue) {
        searchValue = fullNameValue;
      } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (heightValue) {
        searchValue = heightValue;
      } <span class="hljs-keyword">else</span> {
        searchValue = eyeColorValue;
      }

      <span class="hljs-keyword">return</span> searchValue;
    });

    setData(newRows);
};
</code></pre>
<p>Next step is to pass (not call the function) the <code>handleSearch</code> function into the <code>onChange</code> event listener. </p>
<pre><code class="lang-jsx">&lt;input
   type=<span class="hljs-string">"search"</span>
   className=<span class="hljs-string">"form-control-sm border ps-3"</span>
   placeholder=<span class="hljs-string">"Search"</span>
   onChange={handleSearch}
/&gt;
</code></pre>
<p>The value of the data property in the <code>DataTable</code> component will now be the state variable, <code>data</code> instead of <code>rows</code> that was initially passed in.</p>
<pre><code class="lang-jsx">&lt;DataTable
    columns={columns}
    data={data}
    fixedHeader
    title=<span class="hljs-string">"React-Data-Table-Component Tutorial."</span>
    pagination
    selectableRows
/&gt;
</code></pre>
<h2 id="heading-10-view-the-table">10. View the Table</h2>
<p>Run the project in the command line and view the table in a browser:</p>
<p><code>command line
npm run dev</code></p>
<p>The table should look something like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/03/final-result-table.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Figure 11.0</strong> Preview of the resulting table created.</em></p>
<p>You can read through the <a target="_blank" href="https://react-data-table-component.netlify.app/?path=/docs/getting-started-intro--docs">documentation</a> for <em>react-data-table-component</em> as it has more in-depth coverage of the library's usage that goes beyond the scope of this article. </p>
<p>Don't fret if there's a difference in your table from the expected result. The source code in <a target="_blank" href="https://github.com/chelmerrox/react-data-table-tutorial">this repository</a> will guide you.</p>
<p>Happy coding and may your code run smoothly!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
