<?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: Peter Gitonga </title>
    <description>The latest articles on DEV Community by Peter Gitonga  (@pptrgi).</description>
    <link>https://dev.to/pptrgi</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%2F1237824%2F8164bbd1-4d55-430c-ba69-b11fc92b7345.png</url>
      <title>DEV Community: Peter Gitonga </title>
      <link>https://dev.to/pptrgi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pptrgi"/>
    <language>en</language>
    <item>
      <title>Useful CSS Breakpoints for Web Developers</title>
      <dc:creator>Peter Gitonga </dc:creator>
      <pubDate>Thu, 11 Jan 2024 05:17:57 +0000</pubDate>
      <link>https://dev.to/pptrgi/useful-css-breakpoints-for-web-developers-3k35</link>
      <guid>https://dev.to/pptrgi/useful-css-breakpoints-for-web-developers-3k35</guid>
      <description>&lt;p&gt;As a web developer, achieving a responsive and visually pleasing layout across various devices can be a daunting task. After grappling with margin-related challenges in my websites with both Tailwind CSS and vanilla CSS, I found out how to strategically implement CSS breakpoints.&lt;/p&gt;

&lt;p&gt;Breakpoints are markers that tell your site when to adapt to different screen sizes. Let's hear what each has to say.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Small Mobile (e.g. iPhone 4): Up to 320px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Starting at the smallest end, accommodate devices with compact screens like the iPhone 4 to ensure a seamless and visually appealing experience for their users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Mobile: Up to 480px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Expanding the scope slightly, the mobile breakpoint (up to 480px) caters to a broader range of smartphones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Small Devices: 481px - 767px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigating through the territory of small devices, this breakpoint can serve devices with typical mobile and tablet dimensions i.e. small tablets or larger smartphones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Tablets: 768px - 991px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As we move to larger screens, the tablet breakpoint (768px - 991px) provides a layout optimized for tablet devices. On top of improving UX, it also enables make the most of the additional screen real estate&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Large Tablets &amp;amp; Small Laptops: 992px - 1199px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Balancing the transition from tablets to larger screens, 992px - 1199px breakpoint caters to large tablets and small screen laptops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Laptops &amp;amp; Desktops: 1200px - 1919px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For the mainstream computing devices, laptops, and desktops, this breakpoint (1200px - 1919px) optimizes the layout to utilize the increased width. It ensures that your content is elegantly presented without overwhelming the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Extra Large Screens: 1920px and up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, for users with extra-large screens, the 1920px-and-up breakpoint tailors the design to make the most of the available space.&lt;/p&gt;

&lt;h2&gt;
  
  
  At a glance
&lt;/h2&gt;

&lt;p&gt;➨ Small mobile e.g. iPhone 4: up to 320px&lt;br&gt;
➨ Mobile: up to 480px&lt;br&gt;
➨ Small devices: 481px to 767px&lt;br&gt;
➨ Tablets: 768px to 991px&lt;br&gt;
➨ Large tablets &amp;amp; small laptops: 992px to 1199px&lt;br&gt;
➨ Laptops &amp;amp; Desktops: 1200px to 1919px&lt;br&gt;
➨ Extra large screens: 1920px and up&lt;/p&gt;

&lt;p&gt;In conclusion, implementing these breakpoints not only resolved my struggles with margins but also enhanced the overall user experience across the devices used to access those sites. &lt;/p&gt;

&lt;p&gt;Below are the snapshots for setting up these screen breakpoints in Tailwind config and vanilla CSS. &lt;/p&gt;

&lt;p&gt;Vanilla CSS&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmhor3kgrgb97wfk1u4yw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmhor3kgrgb97wfk1u4yw.png" alt="Vanilla CSS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tailwind - rename the property names&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2b9vvxulkxn0nr626x1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2b9vvxulkxn0nr626x1.png" alt="Tailwind CSS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How does your breakpoints' setup look like? Share it on the comments&lt;/p&gt;

</description>
    </item>
    <item>
      <title>15 Essential Lessons of 2023 Worth Sharing</title>
      <dc:creator>Peter Gitonga </dc:creator>
      <pubDate>Sat, 30 Dec 2023 06:57:04 +0000</pubDate>
      <link>https://dev.to/pptrgi/15-essential-lessons-of-2023-worth-sharing-1ni6</link>
      <guid>https://dev.to/pptrgi/15-essential-lessons-of-2023-worth-sharing-1ni6</guid>
      <description>&lt;p&gt;→  Know what you want for yourself, and be true to that. Otherwise you'll see things happen to others and suddenly you're envious/jealous of them for something you didn't even want for yourself in the first place.&lt;/p&gt;

&lt;p&gt;→  Get comfortable with being uncomfortable. It's either you got into discomfort willingly or discomfort will come to you, either way no escape.&lt;/p&gt;

&lt;p&gt;→  There are many future versions of yourself that exist based upon the decisions you make currently.&lt;/p&gt;

&lt;p&gt;→  It's easy to end up average if you're interested and distracted by everything, and never commit to anything. Years pass, and you do a lot of things but never stick to any of them long enough to get rewarded.&lt;/p&gt;

&lt;p&gt;→  If you want growth, you must prepare to be bored, doubted, failed, rejected and challenged. Learn to handle them.&lt;/p&gt;

&lt;p&gt;→  You need 3 daily wins: mental win (create, learn), physical win (running, gym) and financial win.&lt;/p&gt;

&lt;p&gt;→  A person who conquers the fear of embarrassment becomes unstoppable.&lt;/p&gt;

&lt;p&gt;→  There's no competition if you're confident in who you are.&lt;/p&gt;

&lt;p&gt;→  Hardwork improves your optimism, and being truthful boosts your confidence.&lt;/p&gt;

&lt;p&gt;→  The longer you stay consistent, the more fine-tuned your skill becomes.&lt;/p&gt;

&lt;p&gt;→  Go broke learning, investing, building, creating or launching, not shopping.&lt;/p&gt;

&lt;p&gt;→  Doesn't matter how you start, just start.&lt;/p&gt;

&lt;p&gt;→  Give whatever you do your best, but discard expectations.&lt;/p&gt;

&lt;p&gt;→  Doubt kills more dreams than failure ever will.&lt;/p&gt;

&lt;p&gt;→  Once you have accepted your flaws, no one can use them against you.&lt;/p&gt;

</description>
      <category>development</category>
      <category>growth</category>
      <category>2023takeaways</category>
    </item>
    <item>
      <title>Optimize Web Applications for Performance: Code-Splitting and Lazy Loading in React</title>
      <dc:creator>Peter Gitonga </dc:creator>
      <pubDate>Fri, 29 Dec 2023 05:21:13 +0000</pubDate>
      <link>https://dev.to/pptrgi/optimize-web-applications-for-performance-code-splitting-and-lazy-loading-in-react-f31</link>
      <guid>https://dev.to/pptrgi/optimize-web-applications-for-performance-code-splitting-and-lazy-loading-in-react-f31</guid>
      <description>&lt;p&gt;React makes it easy to build small to complex web applications. But the more complex the application gets, the more resources it demands. This makes it necessary to employ various optimization techniques to improve the application’s performance and the overall user satisfaction. In this article, we are going to explore how we can boost performance by code-splitting and lazy loading.&lt;/p&gt;

&lt;p&gt;We’ll start with code splitting, then look at lazy loading, later provide a fallback while loading with Suspense() and finally conclude with useTransition().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Splitting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your React application runs from a single JavaScript bundle file that grows as the application grows. &lt;/p&gt;

&lt;p&gt;The code from individual component files is imported to the application’s top-most file to make up a complete web page or application. That whole code is the "bundle".&lt;/p&gt;

&lt;p&gt;So bundling is the process of following these imported files and combining them to make a single file that can be included on a webpage to load the entire app at once, thanks to a tool like Webpack.&lt;/p&gt;

&lt;p&gt;When you code-split or simply split your code, you break down your code into multiple individual bundle chunks. These individual bundles might be single components in the application or name-exported functions etc. &lt;br&gt;
Splitting the code is achieved by the use of dynamic imports.&lt;/p&gt;

&lt;p&gt;Now on regular imports, you import components on component call, and they look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ComponentName from "./Pathname.js"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But dynamic imports are different, they are imported only when requested for, or when they reach expression. Look like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ComponentName = import("./Pathname.js")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React lazy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React lazy loading is a website optimization technique aiming to boost the site's performance by loading bundles of code on demand. &lt;/p&gt;

&lt;p&gt;This enables avoid issues like increased initial load time, more consumption of bandwidth and system resources, overworking the browser and bad user experience, that may arise as a result of loading the entire application’s code at once.&lt;/p&gt;

&lt;p&gt;It renders components with dynamic imports just like the regular ones except this dynamically imported component’s bundle only loads when the component is rendered. &lt;/p&gt;

&lt;p&gt;React.lazy() accepts a function that calls a dynamic import. The dynamic import returns a promise resolving to a module with a default export containing a React component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const AnotherComponent = React.lazy(() =&amp;gt; import("./Pathname.js"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React Suspense&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you lazily load a component in your application, you need to let React know of it, so it sets up what can be used as placeholder while that lazy component loads on request or during "suspense". &lt;/p&gt;

&lt;p&gt;Suspense() is a component that wraps around your lazy component/s and accepts a DOM element fallback prop  that will be show on the DOM while the lazy component is being loaded.&lt;/p&gt;

&lt;p&gt;On markup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Suspense fallback={&amp;lt;YourPageLoader /&amp;gt;}&amp;gt;
    &amp;lt;Outlet /&amp;gt;
&amp;lt;/Suspense&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;startTransition()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With Suspense(), the DOM is updated with the fallback prop you provided until the next lazy component is rendered. Sometimes you don’t want to totally replace the old UI while waiting for the new UI. To achieve this, use startTransition().&lt;/p&gt;

&lt;p&gt;It freezes the current appearance until the next requested component is rendered, only then the switching takes place.&lt;/p&gt;

&lt;p&gt;One use case is when you want to have a loading spinner above a blurred current UI’s background while the transitioning occurs.&lt;/p&gt;

&lt;p&gt;Example: show the "lazy" dashboard when the showDashboard state is true – toggled by "see board" button on UI&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {useState, useTransition, lazy} from “react”;

const Dashboard = lazy(() =&amp;gt; import(“./DashboardPath.js”));

const Home = () =&amp;gt; {
  const [showDashboard, setShowDashboard] = useState(false);
  const [isPending, startTransition] = useTransition();

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button onClick={e =&amp;gt; {
startTransition(() =&amp;gt; {
setShowDashboard(prev =&amp;gt; !prev)
})
}}&amp;gt;see board&amp;lt;/button&amp;gt;
      &amp;lt;div&amp;gt;
{isPending &amp;amp;&amp;amp; &amp;lt;Dashboard /&amp;gt; }
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, React lazy() is a website optimization technique that renders the split code in dynamic imports on demand. React Suspense() offers a fallback element that shows while the newly requested lazy component loads. React useTransition() helps preserve the current UI until the component is rendered. When used, it improves the application's performance and the user experience.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>performance</category>
      <category>lazyloading</category>
    </item>
    <item>
      <title>Understanding PostgreSQL and MongoDB Databases: Know When to Use Each</title>
      <dc:creator>Peter Gitonga </dc:creator>
      <pubDate>Fri, 22 Dec 2023 16:51:05 +0000</pubDate>
      <link>https://dev.to/pptrgi/understanding-postgresql-and-mongodb-databases-know-when-to-use-each-43ie</link>
      <guid>https://dev.to/pptrgi/understanding-postgresql-and-mongodb-databases-know-when-to-use-each-43ie</guid>
      <description>&lt;p&gt;When it comes to database management systems (DBMS), PostgreSQL and MongoDB will often find themselves in the spotlight. But choosing any of them depends on the specific requirements of your project. In this article we are going to explore them, understand what they are and where each applies best.&lt;/p&gt;

&lt;p&gt;I have seen posts saying "Which is your go-to database?" then goes ahead and lists about four different databases. I don't have a problem with that if it's one's hobby project, or if they're trying to learn. But beyond this, you'll have to fetch from the toolbox the right tool for the job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we proceed, let's understand the terms you might come across:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Data model&lt;/em&gt; - an informal description of a database&lt;br&gt;
&lt;em&gt;Schema&lt;/em&gt; - a blueprint or a formally implemented structure in use by the database e.g. in Postgres, names of tables, names of columns in a table and their corresponding data types.&lt;br&gt;
&lt;em&gt;Mapper&lt;/em&gt; - high-level package helping connect to databases and perform database operations &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;PostgreSQL&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;PostgreSQL or simply Postgres(because no one has time for syllables) is a relational database management system (RDBMS) that follows a structured and tabular (with rows and columns) data model.&lt;/p&gt;

&lt;p&gt;Postgres enforces a predefined schema requiring well-defined structures of the tables that ensures data consistency and integrity.&lt;/p&gt;

&lt;p&gt;It uses SQL (structured query language), a standardized language for managing relational databases, to command the server.&lt;/p&gt;

&lt;p&gt;It's structure consists of records which are rows containing data and tables which are groups of rows and columns. Column names are used as keys when querying for records.&lt;/p&gt;

&lt;p&gt;Some of the Postgres ORM's (Object-Relational Mapper) include Sequelize, pg. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Postgres Applications&lt;/strong&gt;&lt;br&gt;
Use Postgres:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For demanding applications that require complex queries and relationships, advanced data types and indexing options.&lt;/li&gt;
&lt;li&gt;Where data integrity is critical i.e data is accurate, consistent and reliable while within the database. Postgres is ACID compliant.&lt;/li&gt;
&lt;li&gt;It has a mature ecosystem, guaranteeing support, and a wealth of resources.&lt;/li&gt;
&lt;li&gt;Where vertical scalability is more preferred - adding more resources to a single server. Horizontal scaling (distributing servers around the world) in Postgres requires more effort.&lt;/li&gt;
&lt;li&gt;Suitable for systems with
fixed data models like financial systems, CRM systems.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;MongoDB&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;MongoDB is a NoSQL database that follows a document-oriented data model and stores data in JSON-like BSON documents.&lt;/p&gt;

&lt;p&gt;MongoDB allows for dynamic schema or schema-less design making it flexible and agile in accommodating unpredictable future data structure changes, and easy to scale horizontally.&lt;/p&gt;

&lt;p&gt;For query language, it leverages on a number of query operators based on JSON-like documents, which works well with semi-structured and unstructured data. The language is also simple and ease to use.&lt;/p&gt;

&lt;p&gt;It's structure comprises of documents as data, and collections as groups of related documents.&lt;/p&gt;

&lt;p&gt;Some of the MongoDB ODM (Object-Document Mapper) include Mongoose&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MongoDB Applications&lt;/strong&gt;&lt;br&gt;
Choose MongoDB:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the database requires flexibility in adapting to changing data structures without a predefined schema.&lt;/li&gt;
&lt;li&gt;Agility in development is paramount - dynamic/schema less nature of MongoDB makes it agile in development, especially for unpredictable data structures since you won't have to go back adjust a predefined schema for your changes to be acommodated.&lt;/li&gt;
&lt;li&gt;Simplicity and ease of use performing database operations since it uses BSON documents that use JSON-like language.&lt;/li&gt;
&lt;li&gt;Effortlessly scale horizontally to accomodate growing datasets and high write loads.&lt;/li&gt;
&lt;li&gt;Suitable for systems with unrestrictive data models like real-time big data, IOT and CMS systems.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, the choice of the database to use relies on the requirements of your project. Use Postgres for data that requires a predefined schema to ensure data integrity and consistency. On the other hand, MongoDB is the best option for the data whose structure keeps changing over time since its dynamic/schema-less nature makes it flexible to accommodate such changes.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>database</category>
      <category>postgressql</category>
      <category>sql</category>
    </item>
    <item>
      <title>Navigable Websites: A Guide to React Pagination Without Packages</title>
      <dc:creator>Peter Gitonga </dc:creator>
      <pubDate>Thu, 21 Dec 2023 06:34:08 +0000</pubDate>
      <link>https://dev.to/pptrgi/navigable-websites-a-guide-to-react-pagination-without-packages-27bk</link>
      <guid>https://dev.to/pptrgi/navigable-websites-a-guide-to-react-pagination-without-packages-27bk</guid>
      <description>&lt;p&gt;Pagination is a crucial element of web development that enhances user experience by breaking down large sets of content into manageable chunks. As a result websites load faster, and the navigation is improved.&lt;br&gt;
Let me show you how to paginate without installing external dependencies in React.&lt;/p&gt;

&lt;p&gt;Let's start by creating a functional component called Pagination and importing useState().&lt;/p&gt;

&lt;p&gt;We will be working with these sample items, in the allItems array. On markup, each item is displayed on a card.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QMiQzA81--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6awwv4pqio6v4sy1ai4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QMiQzA81--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6awwv4pqio6v4sy1ai4j.png" alt="Original array" width="800" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now initialize states including currentActivePage that'll keep track of the current page, and itemsPerPage that'll define the number of items we need per paginated page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DAL6rBBV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/koj28hvv2k8qvbfa3kyr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DAL6rBBV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/koj28hvv2k8qvbfa3kyr.png" alt="Initialized states" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With our items array and itemsPerPage defined, we can count the number of pages we'll have by dividing itemsPerPage to the allItems array length. This will be useful when displaying page numbers on the UI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NRAQRX36--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya2phzmichkkw4swsuyj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NRAQRX36--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya2phzmichkkw4swsuyj.png" alt="Number of pages" width="800" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On markup, using the numberOfPages digit we got, we create an array from its length. The length will be equal to that digit, and the reason we must use an object with length property is because Array.from() accepts an iterable on that first argument, while the numberOfPages digit is just a number (not iterable). &lt;br&gt;
From that generated array, we extract the indexes and make sure they start at 1 then map through the indexes and return a pageNumber that will be passed as argument to the function handling page change, and also will be displayed on the UI as page links.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--buhte0kY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/io9nw1n9szqd8eacpucq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--buhte0kY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/io9nw1n9szqd8eacpucq.png" alt="Page Links" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Going forward we'll see how to create a part of the entire allItems array with each part being shown on its own page. &lt;br&gt;
For us to show a portion of the entire array, we'll need to slice() the original array. To slice() it we'll require the start and end indexes. &lt;br&gt;
We calculate the start index of each page by first subtracting 1 from the current page's number (subtracting since array indexes start at 0, and our currentActivePage state starts at 1) then multiplying the answer by itemsPerPage. For instance, the start index of page 1 with 6 items per page will be 0 &amp;gt;&amp;gt;&amp;gt; (1 - 1) * 6 = 0&lt;br&gt;
The end index is given by adding itemsPerPage to the start index, i.e. the end index of page 1 in the above example will be 6 &amp;gt;&amp;gt;&amp;gt; 0 + 6 = 6&lt;br&gt;
Each page will have it's own start and end index, different from the other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G9ETEFDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf63gl7hvyamovu8yum0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G9ETEFDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf63gl7hvyamovu8yum0.png" alt="Indexes" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's slice the original array using our start and end index. This returns an array that is part of the original array within the range specified by the indexes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FJQcCU3W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/timdfjmbskmvc0ddc4b6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FJQcCU3W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/timdfjmbskmvc0ddc4b6.png" alt="Sliced Array" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On markup, we show the paginated items from the sliced array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8fTAnK4A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tj4zik83b8eqi54imbt3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8fTAnK4A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tj4zik83b8eqi54imbt3.png" alt="Sliced Array items" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, we will define a function that'll change the current page upon page number click on the UI. Remember when the currentActivePage state changes, new start and end indexes are calculated thus changing the earlier sliced array to a new one that is within the new specified range.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Yp69iOQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1ffdigbt129p9ys2uky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Yp69iOQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1ffdigbt129p9ys2uky.png" alt="Page Change Function" width="800" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, pagination is a great navigation element that helps increase user satisfaction by not overwhelming them with the number of contents displayed, instead it breaks contents into manageable portions, and by loading websites faster since the website will load a section of the entire contents at a time and not as a whole at once.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ux</category>
      <category>react</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
