<?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>Forem: Ewenike Chukwuemeka Emmanuel👨‍💻</title>
    <description>The latest articles on Forem by Ewenike Chukwuemeka Emmanuel👨‍💻 (@ewenikeemmanue4).</description>
    <link>https://forem.com/ewenikeemmanue4</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%2F965032%2F0379ae29-df6b-4110-929f-f4be7457434f.jpg</url>
      <title>Forem: Ewenike Chukwuemeka Emmanuel👨‍💻</title>
      <link>https://forem.com/ewenikeemmanue4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ewenikeemmanue4"/>
    <language>en</language>
    <item>
      <title>Build on Chain Without Smart Contracts</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Mon, 22 Sep 2025 09:54:40 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/build-on-chain-without-smart-contracts-3811</link>
      <guid>https://forem.com/ewenikeemmanue4/build-on-chain-without-smart-contracts-3811</guid>
      <description>&lt;p&gt;One of the issues web2 developers face when trying to build on chain is usually the complexity that comes with web3 and smart contracts.&lt;/p&gt;

&lt;p&gt;Deploying on chain is relatively expensive, this also deters web2 developers from migrating to web3.&lt;/p&gt;

&lt;p&gt;In this article, I will show you a solution to these problems. A way by which you can build on chain without learning solidity, the expensive fees etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The PWR Chain Solution&lt;/strong&gt;: Decoupling Consensus from Execution, PWR Chain redefines blockchain development by introducing a modular architecture that separates consensus from execution. Unlike traditional blockchains, where computation and storage are tightly coupled with the consensus mechanism, PWR Chain operates as a decentralized data layer. This layer serves as an immutable, verifiable source of truth, while allowing developers to process data off-chain using familiar Web2 tools like Python, Java, or SQL.&lt;/p&gt;

&lt;p&gt;The result is a platform that combines the trust and transparency of blockchain with the scalability, flexibility, and accessibility of Web2 development. At the heart of this innovation are Verifiable Immutable Data Applications (VIDAs) — self-contained programs that operate off-chain but anchor their state to PWR Chain’s immutable ledger. VIDAs eliminate the need for smart contracts, enabling developers to build decentralized applications without learning new languages or worrying about gas fees. By decoupling execution from the blockchain, PWR Chain ensures that applications can scale horizontally, integrate seamlessly with existing systems, and remain secure with post-quantum cryptography.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why you should use PWR Chain:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No Smart Contracts, No Problem:&lt;/strong&gt;&lt;br&gt;
Smart contracts often require developers to learn Solidity or other blockchain-specific languages, which can feel alien to those accustomed to Python, Java, or JavaScript. With PWR Chain, developers can write VIDAs in their preferred programming languages, leveraging the tools and frameworks they already know. This lowers the barrier to entry, allowing Web2 developers to build decentralized applications without retraining or retooling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost Efficiency:&lt;/strong&gt;&lt;br&gt;
Gas fees are a major pain point in Web3 development. Deploying and executing smart contracts on traditional blockchains can cost hundreds or even thousands of dollars, depending on network congestion. VIDAs, on the other hand, process data off-chain, eliminating gas fees entirely. Developers only interact with PWR Chain’s ledger to record critical actions or state updates, which are designed to be lightweight and cost-effective. This makes PWR Chain an attractive option for startups, indie developers, and enterprises looking to minimize costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal Scalability:&lt;/strong&gt;&lt;br&gt;
Traditional blockchains often struggle with scalability, as every node must process and store all transactions. PWR Chain’s modular architecture allows developers to add unlimited VIDAs without congesting the network. Each VIDA operates independently, processing its own data off-chain while relying on the blockchain for immutability and verifiability. This ensures that applications can scale to meet the demands of global enterprises or high-traffic consumer apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Familiar Development Environment:&lt;/strong&gt;&lt;br&gt;
PWR Chain’s VIDAs integrate seamlessly with existing Web2 workflows. Developers can use standard IDEs, libraries, and debugging tools to build and test their applications. Whether you’re building a financial app, a supply chain tracker, or a gaming platform, you can leverage the same tools you use for Web2 development while still benefiting from blockchain’s trust guarantees.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enterprise Integration:&lt;/strong&gt;&lt;br&gt;
For enterprises, PWR Chain offers a bridge between legacy systems and decentralized technology. VIDAs can connect to existing ERP, CRM, or database systems via APIs, enabling businesses to anchor critical actions — like financial transactions or supply chain records — to the blockchain without overhauling their infrastructure. This makes PWR Chain an ideal choice for industries like finance, healthcare, and logistics, where auditability and security are paramount.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is How PWR Chain Works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define the Application Logic:&lt;/strong&gt;&lt;br&gt;
Suppose you’re building a decentralized supply chain tracking system. Using Python, you write a VIDA that processes data about shipments, verifies supplier credentials, and calculates delivery timelines. This logic runs off-chain, so you don’t need to worry about gas fees or blockchain-specific constraints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anchor to the Ledger:&lt;/strong&gt;&lt;br&gt;
When a shipment is confirmed, the VIDA records a hash of the transaction data (e.g., supplier ID, timestamp, and delivery details) to PWR Chain’s immutable ledger. This ensures that the transaction is tamper-proof and verifiable by anyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enable Cross-App Communication:&lt;/strong&gt;&lt;br&gt;
If your supply chain app needs to interact with a payment system (another VIDA), PWR Chain’s Conduit Nodes facilitate trustless communication. These nodes follow app-specific rules to ensure secure, decentralized data exchange without relying on centralized intermediaries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verify Results:&lt;/strong&gt;&lt;br&gt;
Anyone — whether a user, auditor, or third party — can verify the application’s state by checking the data anchored to PWR Chain’s ledger. This transparency ensures trust without requiring users to run complex blockchain nodes.&lt;br&gt;
As a Developer, this is how you can use PWR Chain in the real world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finance:&lt;/strong&gt; Build decentralized lending platforms that integrate with existing banking systems, using VIDAs to process loan calculations off-chain while recording approvals on-chain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supply Chain:&lt;/strong&gt; Create transparent, tamper-proof supply chain trackers that sync with enterprise ERP systems, ensuring auditability without sacrificing performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gaming:&lt;/strong&gt; Develop decentralized games where in-game assets are verifiable on-chain, but gameplay logic runs off-chain for low latency and cost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Healthcare:&lt;/strong&gt; Store patient records securely, with VIDAs handling data processing and blockchain anchoring critical updates like treatment histories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The hassle that comes with building on chain has ended since the creation of PWR chain. Web2 developers can now easily build on chain by utilizing the incredible powers of PWR Chain.&lt;/p&gt;

&lt;p&gt;By decoupling consensus from execution and introducing Verifiable Immutable Data Applications (VIDAs), PWR Chain empowers developers to build decentralized applications using familiar Web2 tools like Python, Java, and SQL — without the need for smart contracts, proprietary languages, or expensive gas fees. This revolutionary platform combines the trust and transparency of blockchain with the scalability, flexibility, and cost-efficiency of traditional development, making it accessible to indie developers, startups, and global enterprises alike. (&lt;a href="https://www.pwrlabs.io/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>blockchain</category>
      <category>smartcontract</category>
      <category>web3</category>
    </item>
    <item>
      <title>Don`t Read This Article, You Might Regret It</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Wed, 04 Jun 2025 02:35:30 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/dont-read-this-article-you-might-regret-it-1fl</link>
      <guid>https://forem.com/ewenikeemmanue4/dont-read-this-article-you-might-regret-it-1fl</guid>
      <description>&lt;p&gt;Have you ever been in a position where you wished if you could bookmark social media posts and get reminded of them? Or maybe you are reading an article but you don`t have time to finish it up, you wished if you could bookmark it and get reminded of it later.&lt;/p&gt;

&lt;p&gt;There is a chrome extension that will enable you to bookmark any link (URL) of anything and get reminded of it based on the time you sechulded for it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reminder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The name of this extension is called reminder (reminder), it allows you to bookmark any link and set a reminder for that link. It has a built in calendar that enables you to choose anytime and date you want to be reminded of the link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F36y343rj93bcjok0dcro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F36y343rj93bcjok0dcro.png" alt="Reminder extension" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When it`s your scheduled time, the extension takes you to a new tab with a sound that will grab your attention. In that tab, you will see the link of the thing you bookmarked, you can either click on the link to visit the bookmark or you can close the tab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Persistence&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your bookmarks won`t be deleted if you reboot your PC, the bookmarks are stored on your browser, making them persistent, even if you reboot your PC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Translation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The extension also comes with a translation feature that enables you to translate words from one language to another. It has a dropdown, where you get to choose which language you are translating from, vice versa.&lt;/p&gt;

&lt;p&gt;You can install the extension from chrome web store, &lt;a href="https://chromewebstore.google.com/detail/inldkoocppadplkanceakejnhlgkpiof?utm_source=item-share-cb" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go ahead and start being more productive with Reminder 😊!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>This Chrome Extension will Make You More Productive As A Developer</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Mon, 21 Apr 2025 05:09:44 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/this-chrome-extension-will-make-you-more-productive-as-a-developer-565k</link>
      <guid>https://forem.com/ewenikeemmanue4/this-chrome-extension-will-make-you-more-productive-as-a-developer-565k</guid>
      <description>&lt;p&gt;Have you ever been in a position where you wished if you could bookmark social media posts and get reminded of them? Or maybe you are reading an article but you don`t have time to finish it up, you wished if you could bookmark it and get reminded of it later. &lt;/p&gt;

&lt;p&gt;There is a chrome extension that will enable you to bookmark any link (URL) of anything and get reminded of it based on the time you sechulded for it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reminder&lt;/strong&gt;&lt;br&gt;
The name of this extension is called reminder (&lt;a href="https://chromewebstore.google.com/detail/inldkoocppadplkanceakejnhlgkpiof?utm_source=item-share-cb" rel="noopener noreferrer"&gt;reminder&lt;/a&gt;), it allows you to bookmark any link and set a reminder for that link. It has a built in calendar that enables you to choose anytime and date you want to be reminded of the link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F69tuuytwdnzk0cloist6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F69tuuytwdnzk0cloist6.png" alt="Image of Reminder" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notification&lt;/strong&gt;&lt;br&gt;
When it`s your scheduled time, the extension takes you to a new tab with a sound that will grab your attention. In that tab, you will see the link of the thing you bookmarked, you can either click on the link to visit the bookmark or you can close the tab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Persistence&lt;/strong&gt;&lt;br&gt;
Your bookmarks won`t be deleted if you reboot your PC, the bookmarks are stored on your browser, making them persistent, even if you reboot your PC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Translation&lt;/strong&gt;&lt;br&gt;
The extension also comes with a translation feature that enables you to translate words from one language to another. It has a dropdown, where you get to choose which language you are translating from, vice versa.&lt;/p&gt;

&lt;p&gt;You can install the extension from chrome web store, &lt;a href="https://chromewebstore.google.com/detail/inldkoocppadplkanceakejnhlgkpiof?utm_source=item-share-cb" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go ahead and start being more productive with Reminder 😊!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
    <item>
      <title>How To Build A Dynamic Modal In Next js</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Sat, 05 Apr 2025 08:43:28 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/how-to-build-a-dynamic-modal-in-next-js-gnf</link>
      <guid>https://forem.com/ewenikeemmanue4/how-to-build-a-dynamic-modal-in-next-js-gnf</guid>
      <description>&lt;p&gt;As developers, we want to show users different UIs based on certain conditions. Maybe you want to show different kinds of messages for celebrations, paid users or different kinds of warnings. Creating separate modals for each case can be repetitive and stressful. &lt;/p&gt;

&lt;p&gt;You can easily create a dynamic modal that shows different kinds of messages or UIs to users using &lt;em&gt;logical AND condition&lt;/em&gt;. For this article, we will be using Next.js for our code examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
To follow along, you should have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic knowledge of React or Next.js&lt;/li&gt;
&lt;li&gt;A good understanding of JavaScript fundamentals&lt;/li&gt;
&lt;li&gt;Node.js installed on your machine&lt;/li&gt;
&lt;li&gt;A modern web browser (like Google Chrome)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is Logical AND (&amp;amp;&amp;amp;) condition&lt;/strong&gt;&lt;br&gt;
It is a condition that allows us to evaluate expressions in Javascript and return a value if our expression is &lt;em&gt;truthy.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const data = "success"
{data === "success" &amp;amp;&amp;amp; &amp;lt;p&amp;gt;You are welcome to the world of coding&amp;lt;/p&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our example above, we can only render &lt;em&gt;&lt;p&gt;You are welcome to the world of coding&lt;/p&gt;&lt;/em&gt; if only the data is equal to &lt;em&gt;success&lt;/em&gt;. We can choose any words or value we want to use, you will be able to render the text as long as it's true. You can clearly see what we can do with this condition right? that's good, let's keep going.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function SubmissionRejectionModalPage() {
    const modalRef = useRef&amp;lt;HTMLDivElement&amp;gt;(null);
    const modalContentRef = useRef&amp;lt;HTMLDivElement&amp;gt;(null); // Ref for modal content
    const modalSvc = useContext&amp;lt;ModalService&amp;gt;(ModalSvcContext);

    // Function to close the modal
    const closeModal = () =&amp;gt; {
        modalSvc.closeModal(APP_MODALS.SUBMISSION_REJECTION_MODAL);
    };

const data = "Off-Topic or Misleading";
    return (
        &amp;lt;main
            className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[10]"
            tabIndex={-1}
            ref={modalRef}
        &amp;gt;
            {/* Modal content */}
            &amp;lt;div
                ref={modalContentRef}
                className="w-[343px] p-6 rounded-lg bg-white dark:bg-dark-50 min-h-[200px] md:w-[512px]"
            &amp;gt;
                {/* Modal header */}
                &amp;lt;div className="flex items-center justify-between"&amp;gt;
                    {data === 'Copyright or Plagiarism' &amp;amp;&amp;amp; (
                        &amp;lt;h4 className="text-2xl font-bold leading-9"&amp;gt;Copyright or Plagiarism&amp;lt;/h4&amp;gt;
                    )}
                    {data === 'Low Quality or Lacks Detail' &amp;amp;&amp;amp; (
                        &amp;lt;h4 className="text-2xl font-bold leading-9"&amp;gt;
                            Low Quality or Lacks Detail
                        &amp;lt;/h4&amp;gt;
                    )}
                    {data === 'Spam or Promotional Content' &amp;amp;&amp;amp; (
                        &amp;lt;h4 className="text-2xl font-bold leading-9"&amp;gt;
                            Spam or Promotional Content
                        &amp;lt;/h4&amp;gt;
                    )}
                    {data === 'Duplicate or Already Covered' &amp;amp;&amp;amp; (
                        &amp;lt;h4 className="text-2xl font-bold leading-9"&amp;gt;
                            Duplicate or Already Covered
                        &amp;lt;/h4&amp;gt;
                    )}
                    {data === 'Off-Topic or Misleading' &amp;amp;&amp;amp; (
                        &amp;lt;h4 className="text-2xl font-bold leading-9"&amp;gt;Off-Topic or Misleading&amp;lt;/h4&amp;gt;
                    )}

                    {/* the delete icon */}
                    &amp;lt;i className="fa-solid fa-xmark cursor-pointer" onClick={closeModal}&amp;gt;&amp;lt;/i&amp;gt;
                &amp;lt;/div&amp;gt;

                {/* Modal content text */}

                {data === 'Copyright or Plagiarism' &amp;amp;&amp;amp; (
                    &amp;lt;p className="mt-6 text-base leading-6"&amp;gt;
                        The content includes copyrighted material or is not original. Ensure you
                        have the right to share all elements included.{' '}
                    &amp;lt;/p&amp;gt;
                )}
                {data === 'Low Quality or Lacks Detail' &amp;amp;&amp;amp; (
                    &amp;lt;p className="mt-6 text-base leading-6"&amp;gt;
                        The submission is too vague, unclear, or missing key information. Consider
                        adding more depth or improving readability.{' '}
                    &amp;lt;/p&amp;gt;
                )}
                {data === 'Spam or Promotional Content' &amp;amp;&amp;amp; (
                    &amp;lt;p className="mt-6 text-base leading-6"&amp;gt;
                        Submissions should provide value beyond self-promotion. If relevant, try
                        adding insights or making it more educational.
                    &amp;lt;/p&amp;gt;
                )}
                {data === 'Duplicate or Already Covered' &amp;amp;&amp;amp; (
                    &amp;lt;p className="mt-6 text-base leading-6"&amp;gt;
                        Similar content already exists. Try adding a new angle, unique insights, or
                        a fresh perspective.{' '}
                    &amp;lt;/p&amp;gt;
                )}
                {data === 'Off-Topic or Misleading' &amp;amp;&amp;amp; (
                    &amp;lt;p className="mt-6 text-base leading-6"&amp;gt;
                        The content does not fit the platform's theme or contains unverified
                        information. Please ensure it aligns with Web3 and is factually accurate{' '}
                    &amp;lt;/p&amp;gt;
                )}



                {/* Button to close the modal */}
                &amp;lt;Button className="blue w-full mt-6 text-sm" onClick={closeModal}&amp;gt;
                    Ok, got it!
                &amp;lt;/Button&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/main&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F6ns9r7och1xatq11pb3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F6ns9r7och1xatq11pb3o.png" alt="picture of dynamic modal" width="598" height="498"&gt;&lt;/a&gt;&lt;br&gt;
As you can clearly see that we can render different UIs with the help of &lt;strong&gt;Logical AND (&amp;amp;&amp;amp;) condition&lt;/strong&gt;. We don`t have to create different modals, this allows us to write clean and effective code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
 Logical AND (&amp;amp;&amp;amp;) condition allows us to render a value if the expression is true. With this, we can easily create a dynamic modal that will show different UIs based on the logic. We don`t have to create separate modals for each case, which could be repetitive and stressful.&lt;/p&gt;

&lt;p&gt;You now understand what Logical AND (&amp;amp;&amp;amp;) condition is and how to use it. You can go ahead and flex your newly acquired skills😊.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How To Create A Tooltip With Floating UI</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Sat, 16 Nov 2024 03:09:49 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/how-to-create-a-tooltip-with-floating-ui-4m96</link>
      <guid>https://forem.com/ewenikeemmanue4/how-to-create-a-tooltip-with-floating-ui-4m96</guid>
      <description>&lt;p&gt;In software development, good user experience is usually one of the most important things to consider when building software. You don't have to make your users guess how to use your software application; this might affect the usability of your application, which is not what you want.&lt;/p&gt;

&lt;p&gt;Most users are impatient, they might not be patient enough to explore and see how your app works, but with a tooltip, you can easily guide them through your application like a tour guide.&lt;/p&gt;

&lt;p&gt;Today, we will be discussing how to build a tooltip easily with Floating UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tooltip&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tooltips are small but informative popups that appear when a user hovers over, clicks on, or focuses on an element. Some tooltips might not require a user to trigger them; instead, they can serve as guides when a user visits your application for the first time, providing context and instructions automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Floating UI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Floating UI is an amazing library that will enable you to create awesome tooltips that can easily adjust their positions based on the screen size. You don`t have to worry about responsiveness, Floating UI will handle that for you.&lt;/p&gt;

&lt;p&gt;Sometimes, creating efficient tooltips can be time consuming, it involves some steps that you might find boring to take, that`s why you have to use libraries like Floating UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites you need to understand this article&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic knowledge of React js.&lt;/li&gt;
&lt;li&gt;Basic understanding of javascript.&lt;/li&gt;
&lt;li&gt;You must have Node js installed on your computer (for your React application to run)&lt;/li&gt;
&lt;li&gt;And finally, a web browser like Google Chrome.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let`s install Floating UI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have to install Floating UI in our React js application. And we can do that by running this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @floating-ui/react&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We need to import lots of functions from the Floating UI library, these functions will enable us to create a tooltip effortlessly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import {&lt;br&gt;
 useClick,&lt;br&gt;
 useFloating,&lt;br&gt;
 useInteractions,&lt;br&gt;
 flip,&lt;br&gt;
 offset,&lt;br&gt;
 useDismiss,&lt;br&gt;
} from '@floating-ui/react';&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Destructure useFloating&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
const {&lt;br&gt;
  refs: calendar1Refs,&lt;br&gt;
  floatingStyles: calendar1FloatingStyles,&lt;br&gt;
  context: calendar1Context,&lt;br&gt;
 } = useFloating({&lt;br&gt;
  open: isOpen1,&lt;br&gt;
  onOpenChange: setIsOpen1,&lt;br&gt;
  placement: 'bottom-end',&lt;br&gt;
  middleware: [&lt;br&gt;
   flip({&lt;br&gt;
    fallbackPlacements: ['right'],&lt;br&gt;
   }),&lt;/p&gt;

&lt;p&gt;offset({ mainAxis: 20, crossAxis: 70 }),&lt;br&gt;
  ],&lt;br&gt;
 });&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Refs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This enables us to connect our tooltip with it`s reference effortlessly. Our reference should look like this.&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;i
      className="fa-light fa-calendar cursor-pointer text-gray-500"
            ref={calendar1Refs.setReference}
           &amp;gt;&amp;lt;/i&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While our tooltip should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{isOpen1 &amp;amp;&amp;amp; (
            &amp;lt;div
             className="absolute z-10 bg-white"
             ref={calendar1Refs.setFloating}

            &amp;gt;
             &amp;lt;Calendar onChange={handleSelectDate1} /&amp;gt;
            &amp;lt;/div&amp;gt;
           )}The difference here is that our tooltip reference has “setReference” while our tooltip has “setFloating”. This will enable them to be connect, making sure that the tooltip floats around it`s reference.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;FloatingStyles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The floatingStyles is an object that contains CSS styles which determine the exact position and dimensions of your floating element (like a tooltip) in relation to its reference element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{isOpen2 &amp;amp;&amp;amp; (
          &amp;lt;div
           className="z-[9999]"
           ref={calendar1Refs.setFloating}
           style={calendar1FloatingStyles}
           {...calendar1TooltipFloatingProps()}
          &amp;gt;
           &amp;lt;Calendar
            onChange={(date) =&amp;gt; hanledSelectDate2(date)}
           /&amp;gt;
          &amp;lt;/div&amp;gt;
         )}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Floating UI, context (like calendar1Context in this case) provides a way to manage and share state and interactions across multiple hooks. This helps us to share events like click, hover etc. It also helps to dismiss the interactions seamlessly, ensuring that each tooltip or floating element behaves consistently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const click1 = useClick(calendar1Context);
 const dismissCalendar1ToolTip = useDismiss(calendar1Context);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Open&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The open prop is very important for the visibility of our tooltip. It helps us to manage the visibility of our tooltip based on a component’s internal state.&lt;/p&gt;

&lt;p&gt;We first create a useState with a default value of false so that we can hide the tooltip until a user clicks on it. This useState tracks whether the tooltip is currently open or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [isOpen, setIsOpen] = useState(false);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;onOpenChange&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This callback helps us to update the setIsOpen value. So whenever a user clicks or trigger an event, we will set the false value in the isOpen to true, vice versa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Placement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This helps to determine where to place our tooltip in relation to it`s reference. We can decide to place our tooltip in any of these positions;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;bottom&lt;/li&gt;
&lt;li&gt;bottom-end&lt;/li&gt;
&lt;li&gt;bottom-start&lt;/li&gt;
&lt;li&gt;left&lt;/li&gt;
&lt;li&gt;left-end&lt;/li&gt;
&lt;li&gt;left-start&lt;/li&gt;
&lt;li&gt;right&lt;/li&gt;
&lt;li&gt;right-end&lt;/li&gt;
&lt;li&gt;right-start&lt;/li&gt;
&lt;li&gt;top&lt;/li&gt;
&lt;li&gt;top-end&lt;/li&gt;
&lt;li&gt;top-start&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Flip&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The flip middleware that is inside the middleware array automatically adjusts the floating element’s position if there isn`t enough space in the specified direction. Here, if there’s not enough space below, it will attempt to position it using the fallback placements (['bottom-end']). We can choose any position we want based on available space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;middleware: [
   flip({
    fallbackPlacements: ['bottom-end'],
   }),

    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Offset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This middleware creates spacing between the reference and the floating element. mainAxis: 20 creates a 20px gap in the primary direction (below the reference, in this case), while crossAxis: 50 creates a 50px offset along the perpendicular axis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;middleware: [
   offset({ mainAxis: 20, crossAxis: 50 }),
  ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how the configuration should 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;const [isOpen, setIsOpen] = useState(false);
 const {
  refs: calendar1Refs,
  floatingStyles: calendar1FloatingStyles,
  context: calendar1Context,
 } = useFloating({
  open: isOpen,
  onOpenChange: setIsOpen,
  placement: 'bottom-end',

  middleware: [
   flip({
    fallbackPlacements: ['bottom-end'],
   }),

   offset({ mainAxis: 20, crossAxis: 50 }),
  ],
 });

 const click = useClick(calendar1Context);
 const dismissImageToolTip = useDismiss(calendar1Context);

 const {
  getReferenceProps: calendar1TooltipReference,
  getFloatingProps: calendar1TooltipFloatingProps,
 } = useInteractions([click, dismissImageToolTip]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click this &lt;a href="https://screenrec.com/share/E3FXJaurde" rel="noopener noreferrer"&gt;link&lt;/a&gt; to watch the demo video. &lt;/p&gt;

&lt;p&gt;From the video, you can clearly see that our tooltip adjusts it&lt;code&gt;s position if the space isn&lt;/code&gt;t enough to contain it. It uses the position of the fallbackPlacements we defined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Floating UI provides a powerful and flexible way to implement tooltips in React applications. With its automatic positioning and rich customization options, you can create tooltips that enhance your application’s user experience while maintaining reliable functionality across different devices and screen sizes.&lt;/p&gt;

&lt;p&gt;It involves so many functions and objects like; refs, floatingStyles, context, useState for state management, onOpenChange, placement, flip and offset.&lt;/p&gt;

&lt;p&gt;By following this guide, you now have the knowledge to implement responsive and user-friendly tooltips in your React applications. Experiment with different configurations and middleware to create the perfect tooltip experience for your users.&lt;/p&gt;

&lt;p&gt;Happy coding 😊&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How To Implement Dark/Light Themes in Next.js (React js) with Tailwind CSS</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Mon, 22 Jul 2024 11:29:58 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/how-to-implement-darklight-themes-in-nextjs-react-js-with-tailwind-css-5e98</link>
      <guid>https://forem.com/ewenikeemmanue4/how-to-implement-darklight-themes-in-nextjs-react-js-with-tailwind-css-5e98</guid>
      <description>&lt;p&gt;Having an application or a website that enables users to choose themes is really nice and awesome in this modern day web. These days, people spend most of their time online and they are really hurting their eyes, providing such feature will improve the user experience.&lt;/p&gt;

&lt;p&gt;In this article, we are going to discus how to build a Next js application that will enable users to choose between light and dark themes using Tailwind CSS and make it to be persistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites you need to understand this article&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Basic knowledge of React or Next js.&lt;br&gt;
2.Basic understanding of javascript.&lt;br&gt;
3.You must have Node js installed on your computer (for your React or 4.Next js application to run)&lt;br&gt;
5.And finally, a web browser like Google Chrome.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let`s install Next js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have to install the latest version of Next js by running this command in our terminal.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-next-app@latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will see some questions, asking you to choose what you would like to install along side with Next js. Make sure that you install Tailwind CSS through this way or you can also go to the official website of Tailwind CSS and read the &lt;a href="https://tailwindcss.com/docs/guides/vite" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; to install it manually. You can use your arrow keys to choose what you want to install and then click enter to select it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8zv5rh65h17lfd6tokvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8zv5rh65h17lfd6tokvo.png" alt="Image description" width="800" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let`s start coding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We need to modify the config file of our Tailwind CSS with a special property value so that we can easily change theme of our application. We have to add this darkMode: “class” in the config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import type { Config } from "tailwindcss";

const config: Config = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  darkMode: "class",
  theme: {
    extend: {
      backgroundImage: {
        "gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
        "gradient-conic":
          "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
      },
    },
  },
  plugins: [],
};
export default config;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are checking if the app is done loading, then we will get the theme that the user might have selected previously from the local storage. If the user haven`t selected any theme previously, then we will set the theme to light.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
const [theme, setTheme] = useState&amp;lt;any&amp;gt;(&lt;br&gt;
    typeof window !== "undefined" ? localStorage.getItem("theme") : "light"&lt;br&gt;
  );&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here we are using useffect to select the theme automatically once the page is done loading. We are checking the value in the useState if it is dark theme, once it`s dark theme, we add the dark class to our application which will give it a dark theme effect through the help of Tailwind CSS. We also store the latest value or theme to the local storage and also trigger the function whenever a user updates the theme.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
    if (theme === "dark") {
      document.documentElement.classList.add("dark");
    } else {
      document.documentElement.classList.remove("dark");
    }
    localStorage.setItem("theme", theme);
  }, [theme]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function helps users to switch themes. Here we are using ternary operator to check the value of the theme to update it accordingly. If the value of the theme is dark, we will then update the value of the theme to light, vice versa.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const toggleTheme = () =&amp;gt; {
    setTheme(theme === "dark" ? "light" : "dark");
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are using the dark class in Tailwind CSS to give each element a different kind of style if the application is in dark theme, you can clearly see that you can hide some elements if you don`t want them to be visible in the dark theme.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import { useState, useEffect } from "react";&lt;br&gt;
import DarkModeIcon from "@mui/icons-material/DarkMode";&lt;br&gt;
import WbSunnyIcon from "@mui/icons-material/WbSunny";&lt;/p&gt;

&lt;p&gt;export default function Home() {&lt;br&gt;
  const [theme, setTheme] = useState(&lt;br&gt;
    typeof window !== "undefined" ? localStorage.getItem("theme") : "light"&lt;br&gt;
  );&lt;/p&gt;

&lt;p&gt;useEffect(() =&amp;gt; {&lt;br&gt;
    if (theme === "dark") {&lt;br&gt;
      document.documentElement.classList.add("dark");&lt;br&gt;
    } else {&lt;br&gt;
      document.documentElement.classList.remove("dark");&lt;br&gt;
    }&lt;br&gt;
    localStorage.setItem("theme", theme);&lt;br&gt;
  }, [theme]);&lt;/p&gt;

&lt;p&gt;const toggleTheme = () =&amp;gt; {&lt;br&gt;
    setTheme(theme === "dark" ? "light" : "dark");&lt;br&gt;
  };&lt;br&gt;
  return (&lt;br&gt;
    &lt;br&gt;
      &lt;br&gt;
        {/* logo */}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;svg
      id="logo-88"
      width="40"
      height="41"
      viewBox="0 0 40 41"
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
    &amp;gt;
      &amp;lt;path
        className="ccustom"
        fill-rule="evenodd"
        clip-rule="evenodd"
        d="M13.7146 0.516113C11.4582 0.516113 9.2943 1.41245 7.69881 3.00794L0 10.7067V14.2307C0 16.7204 1.06944 18.9603 2.77401 20.5161C1.06944 22.0719 0 24.3118 0 26.8015V30.3255L7.69881 38.0243C9.2943 39.6198 11.4582 40.5161 13.7146 40.5161C16.2043 40.5161 18.4442 39.4467 20 37.7421C21.5558 39.4467 23.7957 40.5161 26.2854 40.5161C28.5418 40.5161 30.7057 39.6198 32.3012 38.0243L40 30.3255V26.8015C40 24.3118 38.9306 22.0719 37.226 20.5161C38.9306 18.9603 40 16.7204 40 14.2307V10.7067L32.3012 3.00794C30.7057 1.41245 28.5418 0.516113 26.2854 0.516113C23.7957 0.516113 21.5558 1.58555 20 3.29012C18.4442 1.58555 16.2043 0.516113 13.7146 0.516113ZM25.7588 20.5161C25.6629 20.4286 25.5688 20.3387 25.4766 20.2465L20 14.7699L14.5234 20.2465C14.4312 20.3387 14.3371 20.4286 14.2412 20.5161C14.3371 20.6036 14.4312 20.6935 14.5234 20.7857L20 26.2623L25.4766 20.7857C25.5688 20.6935 25.6629 20.6036 25.7588 20.5161ZM22.2222 30.3255L22.2222 32.0085C22.2222 34.2525 24.0414 36.0717 26.2854 36.0717C27.363 36.0717 28.3965 35.6436 29.1585 34.8816L35.5556 28.4845V26.8015C35.5556 24.5575 33.7364 22.7383 31.4924 22.7383C30.4148 22.7383 29.3813 23.1664 28.6193 23.9284L22.2222 30.3255ZM17.7778 30.3255L11.3807 23.9284C10.6187 23.1664 9.58524 22.7383 8.50762 22.7383C6.26359 22.7383 4.44444 24.5575 4.44444 26.8015V28.4845L10.8415 34.8816C11.6035 35.6436 12.637 36.0717 13.7146 36.0717C15.9586 36.0717 17.7778 34.2525 17.7778 32.0085V30.3255ZM17.7778 9.02373V10.7067L11.3807 17.1038C10.6187 17.8658 9.58524 18.2939 8.50762 18.2939C6.26359 18.2939 4.44444 16.4747 4.44444 14.2307V12.5477L10.8415 6.15063C11.6035 5.38864 12.637 4.96056 13.7146 4.96056C15.9586 4.96056 17.7778 6.7797 17.7778 9.02373ZM28.6193 17.1038L22.2222 10.7067L22.2222 9.02373C22.2222 6.7797 24.0414 4.96056 26.2854 4.96056C27.363 4.96056 28.3965 5.38864 29.1585 6.15063L35.5556 12.5477V14.2307C35.5556 16.4747 33.7364 18.2939 31.4924 18.2939C30.4148 18.2939 29.3813 17.8658 28.6193 17.1038Z"
        fill="#FF630B"
      &amp;gt;&amp;lt;/path&amp;gt;
    &amp;lt;/svg&amp;gt;

    {/* links */}
    &amp;lt;ul className="flex items-center justify-between gap-x-3"&amp;gt;
      &amp;lt;li&amp;gt;Home&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;About&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;Contact&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
    {/* toggle */}
    &amp;lt;div className="cursor-pointer" onClick={toggleTheme}&amp;gt;
      &amp;lt;DarkModeIcon className=" dark:hidden" /&amp;gt;
      {/* sun */}
      &amp;lt;WbSunnyIcon className="hidden dark:block" /&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/nav&amp;gt;

  {/* theme con */}
  &amp;lt;div className="flex items-center justify-center w-[500px] mt-[20px] h-[500px] bg-red-600 dark:bg-black"&amp;gt;
    {/* text con */}
    {/* &amp;lt;div&amp;gt; */}
    &amp;lt;h6 className="  text-center dark:hidden"&amp;gt;Light theme&amp;lt;/h6&amp;gt;
    &amp;lt;h6 className=" hidden text-center dark:block dark:text-white"&amp;gt;
      Dark theme
    &amp;lt;/h6&amp;gt;
    {/* &amp;lt;/div&amp;gt; */}
  &amp;lt;/div&amp;gt;
&amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;);&lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5wqd2d4nqee3e6dtt3b4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5wqd2d4nqee3e6dtt3b4.gif" alt="light and dark theme demo" width="462" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Applications with dark and light themes makes it easier for users to have good user experience, giving them the flexibility to choose any theme of their choice which will make them to stay longer in your application leading to increase in sales.&lt;/p&gt;

&lt;p&gt;We can achieve this easily with Nextjs, Tailwind CSS and the browser`s local storage to make it persistent.&lt;/p&gt;

&lt;p&gt;Now with your newly acquired knowledge, go and make the web a better place.&lt;/p&gt;

&lt;p&gt;Happy coding 😊!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tailwindcss</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>How To Verify Forms Using Formik in React js</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Fri, 19 Jul 2024 20:48:00 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/how-to-verify-forms-using-formik-in-react-js-3a4o</link>
      <guid>https://forem.com/ewenikeemmanue4/how-to-verify-forms-using-formik-in-react-js-3a4o</guid>
      <description>&lt;p&gt;In our modern web, forms are a very crucial part of the web, we use it to collect data from users. Forms can be used to onboard users on a platform, for surveys, etc.&lt;/p&gt;

&lt;p&gt;However, managing form state, validation, and submission logic can often become cumbersome and error-prone, especially as forms grow in complexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Formik&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Formik is an awesome library that helps you to manage form states, validations, and other amazing features like showing the number of characters a user is giving to the input field while they are typing.&lt;/p&gt;

&lt;p&gt;In this article, we are going to explore Formik, how to use it for form validation, submission logic, and how easy it is to manage form states.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites you need to understand this article&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Basic knowledge of React js.&lt;br&gt;
2.Basic understanding of how form works in React js.&lt;br&gt;
3.Basic understanding of javascript.&lt;br&gt;
4.You must have Node js installed on your computer (for your React application to run)&lt;br&gt;
5.And finally, a web browser like Google Chrome.&lt;/p&gt;

&lt;p&gt;For this article, I will be using an online code editor called &lt;a href="https://codesandbox.io/" rel="noopener noreferrer"&gt;Codesandbox&lt;/a&gt;. You can go ahead and use it as well, you can also create normal React js application on your computer.&lt;/p&gt;

&lt;p&gt;Codesandbox is an online code editor that allows developers to write code on the web even without their laptops. It safes a lot of time, instead of installing React js, Next js or any other framework, codesandbox allows you to choose them in seconds insteading of wasting time to install them. It allows you to equally select libraries too in seconds. This is amazing right? The most interesting part is that it has free version you can use&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For us to use Formik, we have to install it before we could use it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install formik --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We also have to install another library called yup, yup will help us to validate the input fields based on our preference. We can decide how long an input field should be, the characters it must contain etc.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i yup&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After that, we can setup the formik and start connecting it with our form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useFormik } from 'formik';
import * as yup from "yup";

const formik = useFormik({
    enableReinitialize: true,
    initialValues: {
      name: "",
      surname: "",
      number: "",
    },

    validationSchema: yup.object({
      name: yup
        .string()
        .trim()
        .max(10, "name cannot be more than 10 characters"),

      surname: yup
        .string()
        .trim()
        .max(10, "Surname cannot be more than 10 characters"),

      number: yup
        .string()
        .trim()
        .max(5, "Your number cannot be more than 5 digits"),
    }),

    onSubmit: (values) =&amp;gt; {},
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can clearly see how I used yup to decide how long an input field should be, you can also checkmate passwords, links, etc. with Yup.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let`s create the form&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have to create the form and connect the input fields with the Formik, we have to make sure that the name we are giving the input fields matches with its reference in Formik initialValues.&lt;/p&gt;

&lt;p&gt;Check the input field below, you can clearly see that the name is qual to the name in the initialValues on the formik setup. Without this, you might experience issues with your input field.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
&amp;lt;input&lt;br&gt;
              type="text"&lt;br&gt;
              placeholder="Your name"&lt;br&gt;
              name="name"&lt;br&gt;
              value={formik.values.name}&lt;br&gt;
              onChange={formik.handleChange}&lt;br&gt;
              onBlur={formik.handleBlur}&lt;br&gt;
            /&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;p&gt;import * as yup from "yup";&lt;br&gt;
import { useFormik } from "formik";&lt;br&gt;
import { useState } from 'react';&lt;/p&gt;

&lt;p&gt;export default function Form() {&lt;br&gt;
const [isSubmitting, setIsSubmitting] = useState(false);&lt;br&gt;
  const [submissionError, setSubmissionError] = useState(null);&lt;br&gt;
  const formik = useFormik({&lt;br&gt;
    enableReinitialize: true,&lt;br&gt;
    initialValues: {&lt;br&gt;
      name: "",&lt;br&gt;
      surname: "",&lt;br&gt;
      number: "",&lt;br&gt;
    },&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validationSchema: yup.object({
  name: yup
    .string()
    .trim()
    .max(10, "name cannot be more than 10 characters"),

  surname: yup
    .string()
    .trim()
    .max(10, "Surname cannot be more than 10 characters"),

  number: yup
    .string()
    .trim()
    .max(5, "Your number cannot be more than 5 digits"),
}),

 onSubmit: async (values) =&amp;gt; {
  setIsSubmitting(true);
  setSubmissionError(null);

  try {
    const response = await axios.post('/api/submit', values);
    console.log('Form submitted successfully:', response.data);
    // Optionally reset form
    formik.resetForm();
  } catch (error) {
    setSubmissionError(error.message || 'Failed to submit form');
  } finally {
    setIsSubmitting(false);
  }
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;});&lt;br&gt;
  return (&lt;br&gt;
    &lt;br&gt;
      &lt;br&gt;
        &lt;br&gt;
          {/* label con */}&lt;br&gt;
          &lt;br&gt;
            Your name&lt;br&gt;
            &lt;/p&gt;
&lt;h6&gt;{formik.values.name.length}/10&lt;/h6&gt;
&lt;br&gt;
          
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      {/* input control */}
      &amp;lt;div className="input-control"&amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Your name"
          name="name"
          value={formik.values.name}
          onChange={formik.handleChange}
          onBlur={formik.handleBlur}
        /&amp;gt;
      &amp;lt;/div&amp;gt;

      {formik.touched.name &amp;amp;&amp;amp; formik.errors.name &amp;amp;&amp;amp; (
        &amp;lt;div className="error"&amp;gt;{formik.errors.name}&amp;lt;/div&amp;gt;
      )}
    &amp;lt;/div&amp;gt;

    {/* surname con */}
    &amp;lt;div&amp;gt;
      {/* label con */}
      &amp;lt;div className="flex-con"&amp;gt;
        &amp;lt;label htmlFor=""&amp;gt;Your surname&amp;lt;/label&amp;gt;
        &amp;lt;h6&amp;gt;{formik.values.surname.length}/10&amp;lt;/h6&amp;gt;
      &amp;lt;/div&amp;gt;
      {/* input control */}

      &amp;lt;div className="input-control"&amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Your surname"
          name="surname"
          value={formik.values.surname}
          onChange={formik.handleChange}
          onBlur={formik.handleBlur}
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      {formik.touched.surname &amp;amp;&amp;amp; formik.errors.surname &amp;amp;&amp;amp; (
        &amp;lt;div className="error"&amp;gt;{formik.errors.surname}&amp;lt;/div&amp;gt;
      )}
    &amp;lt;/div&amp;gt;

    {/*  number con */}
    &amp;lt;div&amp;gt;
      &amp;lt;div className="flex-con"&amp;gt;
        &amp;lt;label htmlFor=""&amp;gt;Your number&amp;lt;/label&amp;gt;
        &amp;lt;h6&amp;gt;{formik.values.number.toString().length}/5&amp;lt;/h6&amp;gt;
      &amp;lt;/div&amp;gt;

      {/* input control */}
      &amp;lt;div className="input-control"&amp;gt;
        &amp;lt;input
          type="number"
          placeholder="Your number"
          name="number"
          value={formik.values.number}
          onChange={formik.handleChange}
          onBlur={formik.handleBlur}
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      {formik.touched.number &amp;amp;&amp;amp; formik.errors.number &amp;amp;&amp;amp; (
        &amp;lt;div className="error"&amp;gt;{formik.errors.number}&amp;lt;/div&amp;gt;
      )}
    &amp;lt;/div&amp;gt;

    &amp;lt;button
      className={`  ${formik.dirty ? "btn" : "btn-grey"}`}
      type="button"
      disabled={isSubmitting || !(formik.isValid &amp;amp;&amp;amp; formik.dirty)}
    &amp;gt;
     {isSubmitting ? 'Submitting...' : 'Send'}
    &amp;lt;/button&amp;gt;
  &amp;lt;/form&amp;gt;
&amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;);&lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fg69xp8dsy8ioimh32l3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fg69xp8dsy8ioimh32l3s.png" alt="formik" width="681" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The enableReinitialize&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The enableReinitialize option in the useFormik hook is a crucial feature that allows Formik to reinitialize the form state with new initial values. By default, Formik only initializes the form state once, and subsequent changes to the initial values will not be reflected in the form state. By setting enableReinitialize to true, Formik will reinitialize the form state with new initial values whenever the initialValues prop changes. This is particularly useful when working with dynamic forms, where the initial values may change based on user interactions or other application state changes. By enabling reinitialization, you can ensure that your form state remains up-to-date and accurate, even as the initial values change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can clearly see how we are accessing the value of each input field from Formik in real time without using any useState.&lt;/p&gt;

&lt;p&gt;Make sure that you are really accessing the right state, as you can see from the example, we are correctly accessing each state value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Onchange&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are using the built-in onChange function in Formik to update each input state while the user is typing. So we don&lt;code&gt;t really need to create anything else, that&lt;/code&gt;s cool right 😊?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OnBlur&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are also using the onBlur function in formik to let Formik know when an input field loses focus so that it can check if a user is actually giving the right input value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The error message&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We display the error message we specified in yup for each input field whenever the input field doesn`t match with our validation. You can clearly see that in the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The length of the input value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can also show the length of an input value while a user is typing, this will help users to know the length of what they are typing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The button&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The style of the button is dynamic, when all the input fields are empty, the button will have some certain kind of style. But when we have a value in one of the input fields, the style of the button changes as well.&lt;/p&gt;

&lt;p&gt;The button is also disabled if we don`t have any value in the input fields and the content of the button is dynamic too. We also disable the button when we are submitting the form data.&lt;/p&gt;

&lt;p&gt;This will prevent users from submitting empty forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OnSubmit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The submit function allows us to send the form data to our desired endpoint or location. You can write any logic there, just make sure that the submit function is connected to the form so that it can be triggered when a user clicks on the send button.&lt;/p&gt;

&lt;p&gt;In our case, we are trying to send the form data to an endpoint, although it`s not real. But the logic is sending the form data to an endpoint with the help of Axios.&lt;/p&gt;

&lt;p&gt;As you can see, it`s very easy to manage and validate form values with Formik.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Managing form states and validation are very essential steps to making sure that we are actually getting the right data from users but doing this is usually not a work in the park.&lt;/p&gt;

&lt;p&gt;Formik is a very amazing library that helps us to manage form data effectively, it also has other amazing features like getting the length of an input value, the handleChange function, the handleBlur function, error messages, etc.&lt;/p&gt;

&lt;p&gt;With the combination of yup, we can actually validate the input values based on our preference.&lt;/p&gt;

&lt;p&gt;I hope you now understand the basics of Formik and how to verify forms with Formik and Yup.&lt;/p&gt;

&lt;p&gt;You can study more about Formik &lt;a href="https://formik.org/docs/overview" rel="noopener noreferrer"&gt;here&lt;/a&gt; and Yup &lt;a href="https://www.npmjs.com/package/yup" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy coding 😊!&lt;/p&gt;


</description>
      <category>webdev</category>
      <category>formik</category>
      <category>javascript</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>How To Use TanStack (React Query)</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Fri, 19 Jul 2024 20:01:06 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/how-to-use-tanstack-react-query-52bd</link>
      <guid>https://forem.com/ewenikeemmanue4/how-to-use-tanstack-react-query-52bd</guid>
      <description>&lt;p&gt;In today modern web development, HTTP request is very crucial for applications, so the need for efficient data management becomes increasingly critical. This article will expose you to Tanstack, it`s key features and how to get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tanstack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tanstack is an amazing library for data management in applications, it addresses data management issues for asynchronous data operations. It helps developers to carryout HTTP requests easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is HTTP request?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTTP request (Hypertext Transfer Protocol) is usually a message sent by a browser to the server to initiate a communication and to request data or actions. HTTP is very important to the World Wide Web, it is a fundamental part of the web. Without it, we might not have applications.&lt;/p&gt;

&lt;p&gt;HTTP request allows frontend applications to perform GET, POST, PUT, DELETE, PATCH etc actions on the server through an endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of using Tanstack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Caching and Data Synchronization: With built-in caching mechanisms, tanstack optimizes the performance of your application by storing data locally. This reduces the number of requests, which will make your application to be much faster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimistic Updates&lt;/strong&gt;: Tanstack facilitates optimistic updates, this enables developers to update the UI accordingly. It has amazing states like, the error, isLoading. You can use these to conditionally render a loading state while the data is loading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automatic Pagination and Infinite Loading&lt;/strong&gt;: Handling large datasets becomes effortless with tanstack’s support for automatic pagination and infinite loading. Developers can seamlessly fetch and display data in chunks, enhancing application performance and user experience.&lt;br&gt;
How to use Tanstack&lt;/p&gt;

&lt;p&gt;First, we have to install tanstack by running &lt;code&gt;npm i react-query&lt;/code&gt; on our terminal.&lt;/p&gt;

&lt;p&gt;We have to inject the QueryClientProvider in our application so that we can be able to use Tanstack. We will also provide it with the queryClient as a prop. You can create this in the index.js file of your application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
&lt;/code&gt;import React from "react";&lt;br&gt;
import ReactDOM from "react-dom/client";&lt;br&gt;
import "./index.css";&lt;br&gt;
import App from "./App";&lt;br&gt;
import reportWebVitals from "./reportWebVitals";&lt;br&gt;
import Nav from "./Nav";&lt;br&gt;
import { BrowserRouter } from "react-router-dom";&lt;br&gt;
import { QueryClientProvider, QueryClient } from "react-query";&lt;/p&gt;

&lt;p&gt;const root = ReactDOM.createRoot(document.getElementById("root"));&lt;br&gt;
const queryClient = new QueryClient();&lt;br&gt;
root.render(&lt;br&gt;
  &lt;br&gt;
    &lt;br&gt;
      &lt;br&gt;
        &lt;br&gt;
        &lt;br&gt;
      &lt;br&gt;
    &lt;br&gt;
  &lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;reportWebVitals();&lt;code&gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;How To Fetch Data With Tanstack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, we are going to fetch some data from an endpoint using Tanstack. We need to import useQuery from react-query (Tanstack).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import { useQuery } from "react-query";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we will destructure it and get the isLoading, data and the error states from it. These states will enable us to carryout the optimistic UI updates. This will enable us to conditionally render different UI based on the state of the data.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
const id = useParams()&lt;br&gt;
  const { isLoading, data, error } = useQuery(["post", id.id], () =&amp;gt;&lt;br&gt;
    getSignleQueryFunc(id.id)&lt;br&gt;
  )&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we have to pass a query, a query is a declarative dependency on an asynchronous source of data that is tied to a unique key. This query will help us to fetch data. In our case, we have an array of a string (post) an the id of each post. It doesn`t really matter, just make sure that it is unique.&lt;/p&gt;

&lt;p&gt;Here is an example from the Tanstack documentation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from 'react-query'

function App() {
  const info = useQuery('todos', fetchTodoList)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we have to include the query function, this query function enables us to fetch the data from an endpoint. In our case, we created our function in a separate file and imported it. Here is our query function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function getSignleQueryFunc(id) {
  const response = await fetch(
    `https://jsonplaceholder.typicode.com/posts/${id}`
  );
  return response.json();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the final result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from "react-query";

import { getSignleQueryFunc } from "./getSignlePost";
import { useParams } from "react-router-dom";

export default function Posts() {
  const id = useParams();
  const { isLoading, data, error } = useQuery(["post", id.id], () =&amp;gt;
    getSignleQueryFunc(id.id)
  );

  if (error &amp;amp;&amp;amp; data == undefined) return &amp;lt;p&amp;gt;Error fetching post&amp;lt;/p&amp;gt;;

  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;post&amp;lt;/h1&amp;gt;
      &amp;lt;div&amp;gt;
        {isLoading ? (
          &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;
        ) : (
          &amp;lt;div&amp;gt;
            &amp;lt;h3&amp;gt;{data.title}&amp;lt;/h3&amp;gt;
            &amp;lt;p&amp;gt;{data.body}&amp;lt;/p&amp;gt;
            &amp;lt;p&amp;gt;the number is {data.id}&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
        )}
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can clearly see how easy it is to use Tanstack (react query) to fetch data. You don`t need to use useStates anymore to determine the state of your data. In this example, we fetched single posts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fuoxly7zojjeywbe6rxin.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fuoxly7zojjeywbe6rxin.gif" alt="React query" width="770" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mutations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mutations enables you to create, delete and update data. Tanstack has useMutation which you will use to create, delete and update data.&lt;/p&gt;

&lt;p&gt;We have to pass the mutation function to the useMutation, and then supply the function with the necessary parameters for the specific mutation operation you want to perform. In our case, we will be updating the posts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is how it is done&lt;/strong&gt;&lt;br&gt;
`&lt;br&gt;
import { editPostFunc } from "./editPost";&lt;br&gt;
import { useQuery, useMutation } from "react-query";&lt;br&gt;
import { useParams } from "react-router-dom";&lt;br&gt;
import { useState, useEffect } from "react";&lt;br&gt;
import { getSignleQueryFunc } from "./getSignlePost";&lt;/p&gt;

&lt;p&gt;export default function UpdatePost() {&lt;br&gt;
  const id = useParams();&lt;br&gt;
  const { data } = useQuery(["post", id.id], () =&amp;gt; getSignleQueryFunc(id.id));&lt;br&gt;
  const [title, setTitle] = useState("");&lt;br&gt;
  const [body, setBody] = useState("");&lt;/p&gt;

&lt;p&gt;useEffect(() =&amp;gt; {&lt;br&gt;
    if (data) {&lt;br&gt;
      setTitle(data.title || "");&lt;br&gt;
      setBody(data.body || "");&lt;br&gt;
    }&lt;br&gt;
  }, [data]);&lt;/p&gt;

&lt;p&gt;const itemUpdate = useMutation(editPostFunc, {&lt;br&gt;
    onSuccess: () =&amp;gt; {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  console.log("Post updated successfully");
},
onError: (error) =&amp;gt; {

  console.error("Error updating post:", error);
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;const handleSubmit = (e) =&amp;gt; {&lt;br&gt;
    e.preventDefault();&lt;br&gt;
    const updatedData = {&lt;br&gt;
      id: id.id,&lt;br&gt;
      title: title,&lt;br&gt;
      body: body,&lt;br&gt;
      userId: data.userId,&lt;br&gt;
    };&lt;br&gt;
    itemUpdate.mutate(updatedData);&lt;br&gt;
     };&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &lt;br&gt;
      &lt;/p&gt;
&lt;h1&gt;hello everyone&lt;/h1&gt;
&lt;br&gt;
      &lt;br&gt;
        
          type="text"&lt;br&gt;
          placeholder="first input"&lt;br&gt;
          name="title"&lt;br&gt;
          value={title}&lt;br&gt;
          onChange={(e) =&amp;gt; setTitle(e.target.value)}&lt;br&gt;
        /&amp;gt;&lt;br&gt;
        
          type="text"&lt;br&gt;
          placeholder="second input"&lt;br&gt;
          name="body"&lt;br&gt;
          value={body}&lt;br&gt;
          onChange={(e) =&amp;gt; setBody(e.target.value)}&lt;br&gt;
        /&amp;gt;&lt;br&gt;
        click&lt;br&gt;
      

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;);&lt;br&gt;
}`&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9yoskyp7qe68bx6o65ri.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9yoskyp7qe68bx6o65ri.gif" alt="React query" width="420" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is how our editPostFunc looks like&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
export async function editPostFunc(updatedData) {&lt;br&gt;
  const res = await fetch(&lt;br&gt;
&lt;/code&gt;&lt;a href="https://jsonplaceholder.typicode.com/posts/$%7BupdatedData.id%7D%60" rel="noopener noreferrer"&gt;https://jsonplaceholder.typicode.com/posts/${updatedData.id}`&lt;/a&gt;,&lt;br&gt;
    {&lt;br&gt;
      method: "PUT",&lt;br&gt;
      body: JSON.stringify({&lt;br&gt;
        id: updatedData.id,&lt;br&gt;
        title: updatedData.title,&lt;br&gt;
        body: updatedData.body,&lt;br&gt;
        userId: updatedData.userId,&lt;br&gt;
      }),&lt;br&gt;
      headers: {&lt;br&gt;
        "Content-type": "application/json; charset=UTF-8",&lt;br&gt;
      },&lt;br&gt;
    }&lt;br&gt;
  );&lt;br&gt;
  return res.json();&lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we are fetching each post and storing the values in the useStates so that we can be able to edit them in the input fields. Once we are done editing it, we call the handleSubmit function. In this function, we are creating an object with the necessary property values, this includes the states we updated.&lt;/p&gt;

&lt;p&gt;We will then send the object to the mutation function for the update. We also check if the edit was successful or not by console logging the result we are getting whenever we try to update a post.&lt;/p&gt;

&lt;p&gt;You can clearly see how easy it is to carryout HTTP requests with Tanstack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Difference between useQuery and useMutation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use cases&lt;/strong&gt;: useQuery is used to fetch data while useMutation is used for modifying data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTTP request is a very essential part of modern web development, it allow browsers to initiate a communication with a server to perform some actions like GET, POST, PUT, DELETE, PATCH etc. Tanstack on the other hand helps to make things easier for developers, it has some many benefits like optimistic UI updates, simplified data fetching etc.&lt;/p&gt;

&lt;p&gt;I believe you have seen how easy it is to use Tanstack to handle HTTP requests and data management. Check out the Tanstack documentation &lt;a href="https://tanstack.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt; for more understanding and to explore other features of Tanstack.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to build filter functionality in an e-commerce website in React js</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Sat, 06 Jan 2024 11:48:38 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/how-to-build-filter-functionality-in-an-e-commerce-website-in-react-js-3b2a</link>
      <guid>https://forem.com/ewenikeemmanue4/how-to-build-filter-functionality-in-an-e-commerce-website-in-react-js-3b2a</guid>
      <description>&lt;p&gt;Nowadays, e-commerce applications comes with lots of items in them. These items can sometimes be very had for customers to find what they are looking for easily. Most customers are impatient to be scrolling and be looking for what they want. &lt;/p&gt;

&lt;p&gt;As developers, our goals is to solve problems and make life easier for users. Adding a filter functionality to an e-commerce application will not only help customer to find what they are looking for easily, it will also improve the user experience which will lead to increase in sales.&lt;/p&gt;

&lt;p&gt;Today, we will discuss how to implement filter functionality in React js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites you need to understand this article&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic understanding of HTML.&lt;/li&gt;
&lt;li&gt;Basic understanding of CSS.&lt;/li&gt;
&lt;li&gt;Basic understanding of JavaScript.&lt;/li&gt;
&lt;li&gt;Basic understanding of React js.&lt;/li&gt;
&lt;li&gt;You must have Node js installed on your computer (for your React application to run)&lt;/li&gt;
&lt;li&gt;And finally, a web browser like Google Chrome.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this article, I will be using an online code editor called &lt;a href="https://codesandbox.io/" rel="noopener noreferrer"&gt;Codesandbox&lt;/a&gt;. You can go ahead and use it as well, you can also create normal React js application on your computer.&lt;/p&gt;

&lt;p&gt;Codesandbox is an online code editor that allows developers to write code on the web even without their laptops. It safes a lot of time, instead of installing React js, Next js or any other framework, codesandbox allows you to choose them in seconds insteading of wasting time to install them. It allows you to equally select libraries too in seconds. This is amazing right? The most interesting part is that it has free version you can use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let's dive into the exciting world of React.js and start building our filter functionality!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let`s talk about the filter method in JavaScript. Filter method in JavaScript returns the items in an array that matches with the logic assign to it.&lt;br&gt;
It returns a copy of items that satisfy a specified condition.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
const languages = ["java", "php", "javascript", "css" "c"];&lt;/p&gt;

&lt;p&gt;const selectedLanguages = languages.filter((lang)=&amp;gt; lang.length == 3)&lt;br&gt;
console.log(selectedLanguages)&lt;br&gt;
 // expected result is css and php&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;br&gt;
Why are we getting only css and php? because these are the only items in the array that have 3 letters. Every other items in the array is either above or below 3 letters. If you check the logic of our code, you will clearly see that we are looking for items with 3 letters.&lt;/p&gt;

&lt;p&gt;That is how filter method works in JavaScript, it returns items that matches with the logic you assign to it. In our case, we store those items in a variable called &lt;code&gt;selectedLanguages&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import { useState } from "react";&lt;br&gt;
import "./styles.css";&lt;/p&gt;

&lt;p&gt;export default function App() {&lt;br&gt;
  const data = [&lt;br&gt;
    {&lt;br&gt;
      id: 1,&lt;br&gt;
      name: "Shirt",&lt;br&gt;
      price: 300,&lt;br&gt;
      image: "&lt;a href="https://m.media-amazon.com/images/I/81n3upEij0L._AC_UL320_.jpg" rel="noopener noreferrer"&gt;https://m.media-amazon.com/images/I/81n3upEij0L._AC_UL320_.jpg&lt;/a&gt;",&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      id: 2,&lt;br&gt;
      name: "Shoe",&lt;br&gt;
      price: 10,&lt;br&gt;
      image: "&lt;a href="https://m.media-amazon.com/images/I/61VrbOtzDXL._AC_UL320_.jpg" rel="noopener noreferrer"&gt;https://m.media-amazon.com/images/I/61VrbOtzDXL._AC_UL320_.jpg&lt;/a&gt;",&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      id: 3,&lt;br&gt;
      name: "Watch",&lt;br&gt;
      price: 30,&lt;br&gt;
      image: "&lt;a href="https://m.media-amazon.com/images/I/71E00KpHBvL._AC_UL320_.jpg" rel="noopener noreferrer"&gt;https://m.media-amazon.com/images/I/71E00KpHBvL._AC_UL320_.jpg&lt;/a&gt;",&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      id: 4,&lt;br&gt;
      name: "Bangle",&lt;br&gt;
      price: 5,&lt;br&gt;
      image: "&lt;a href="https://m.media-amazon.com/images/I/613xQziz5HL._AC_UL320_.jpg" rel="noopener noreferrer"&gt;https://m.media-amazon.com/images/I/613xQziz5HL._AC_UL320_.jpg&lt;/a&gt;",&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      id: 5,&lt;br&gt;
      name: "Necklace",&lt;br&gt;
      price: 300,&lt;br&gt;
      image: "&lt;a href="https://m.media-amazon.com/images/I/6191eeBha+L._AC_UL320_.jpg" rel="noopener noreferrer"&gt;https://m.media-amazon.com/images/I/6191eeBha+L._AC_UL320_.jpg&lt;/a&gt;",&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      id: 6,&lt;br&gt;
      name: "Ring",&lt;br&gt;
      price: 3,&lt;br&gt;
      image: "&lt;a href="https://m.media-amazon.com/images/I/618fjry4-tL._AC_UL320_.jpg" rel="noopener noreferrer"&gt;https://m.media-amazon.com/images/I/618fjry4-tL._AC_UL320_.jpg&lt;/a&gt;",&lt;br&gt;
    },&lt;br&gt;
  ];&lt;br&gt;
  const [items, setItems] = useState(data);&lt;/p&gt;

&lt;p&gt;const pricesCheck = (itemPrice) =&amp;gt; {&lt;br&gt;
    const newItems = data.filter((product) =&amp;gt; product.price &amp;lt;= itemPrice);&lt;br&gt;
    setItems(newItems);&lt;br&gt;
  };&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &lt;/p&gt;
&lt;br&gt;
      &lt;h3&gt;Search by prices&lt;/h3&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;button onClick={() =&amp;gt; pricesCheck(5)}&amp;gt;$5&amp;lt;/button&amp;gt;
  &amp;lt;button onClick={() =&amp;gt; pricesCheck(10)}&amp;gt;$10&amp;lt;/button&amp;gt;
  &amp;lt;button onClick={() =&amp;gt; pricesCheck(15)}&amp;gt;$15&amp;lt;/button&amp;gt;
  &amp;lt;button onClick={() =&amp;gt; pricesCheck(20)}&amp;gt;$20&amp;lt;/button&amp;gt;
  &amp;lt;button onClick={() =&amp;gt; pricesCheck(300)}&amp;gt;$300&amp;lt;/button&amp;gt;

  &amp;lt;div className="items-con"&amp;gt;
    {items.map((item) =&amp;gt; {
      return (
        &amp;lt;div className="menu-item-con" key={item.id}&amp;gt;
          &amp;lt;img src={item.image} alt="" /&amp;gt;
          &amp;lt;div className="item-name-price-con"&amp;gt;
            &amp;lt;p className="food-title"&amp;gt;{item.name}&amp;lt;/p&amp;gt;
            &amp;lt;p&amp;gt;${item.price}&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;p&amp;gt;
            Lorem ipsum, dolor sit amet consectetur adipisicing elit.
            Provident eveniet suscipit atque eius ab sunt cum perspiciatis
            harum laborum natus?
          &amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
      );
    })}
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;br&gt;
Here is the result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ffpsuspkkqve608o8ret7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ffpsuspkkqve608o8ret7.gif" alt="filter method" width="204" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let`s break the code down&lt;/strong&gt;&lt;br&gt;
We created an array of objects, which is obviously the items in our application. I intentionally used this method so that you can understand me better. In a real world example, the items might be coming from an API.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const data = [
    {
      id: 1,
      name: "Shirt",
      price: 300,
      image: "https://m.media-amazon.com/images/I/81n3upEij0L._AC_UL320_.jpg",
    },
    {
      id: 2,
      name: "Shoe",
      price: 10,
      image: "https://m.media-amazon.com/images/I/61VrbOtzDXL._AC_UL320_.jpg",
    },
    {
      id: 3,
      name: "Watch",
      price: 30,
      image: "https://m.media-amazon.com/images/I/71E00KpHBvL._AC_UL320_.jpg",
    },
    {
      id: 4,
      name: "Bangle",
      price: 5,
      image: "https://m.media-amazon.com/images/I/613xQziz5HL._AC_UL320_.jpg",
    },
    {
      id: 5,
      name: "Necklace",
      price: 300,
      image: "https://m.media-amazon.com/images/I/6191eeBha+L._AC_UL320_.jpg",
    },
    {
      id: 6,
      name: "Ring",
      price: 3,
      image: "https://m.media-amazon.com/images/I/618fjry4-tL._AC_UL320_.jpg",
    },
  ];
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You can use this free API endpoint to access random list of items that you can render and filter based on your preference. Here is the &lt;a href="https://jsonplaceholder.typicode.com/" rel="noopener noreferrer"&gt;website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We then created a useState where we stored those array of objects which will enable us to map through them and render them on the screen. This approach will also help us to determine what we will render.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [items, setItems] = useState(data);
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;We also created a function where we made use of the JavaScript filter method to determine which itmes we want to render. As you can see, we instructed JavaScript to only return items that matches with the logic we gave and store them in a variable called &lt;code&gt;newItems&lt;/code&gt;. After that, we update the items state with the newItems so that we can render those items we want on the screen.&lt;/p&gt;

&lt;p&gt;The pricesCheck function we created has a parameter called &lt;code&gt;itemPrice&lt;/code&gt;. Whenever a user clicks on the button, the function will be called. Each button has a specific price on them (argument), which will help users to determine price range of items they want to see.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pricesCheck = (itemPrice) =&amp;gt; {
    const newItems = data.filter((product) =&amp;gt; product.price &amp;lt;= itemPrice);
    setItems(newItems);
  };
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The remaining part is the jsx where we render each items and the buttons for filtering.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
      &amp;lt;div className="btns-con"&amp;gt;
        &amp;lt;div className="prices"&amp;gt;
          &amp;lt;p&amp;gt;Search by prices&amp;lt;/p&amp;gt;
          &amp;lt;button onClick={() =&amp;gt; pricesCheck(5)}&amp;gt;$5&amp;lt;/button&amp;gt;
          &amp;lt;button onClick={() =&amp;gt; pricesCheck(10)}&amp;gt;$10&amp;lt;/button&amp;gt;
          &amp;lt;button onClick={() =&amp;gt; pricesCheck(15)}&amp;gt;$15&amp;lt;/button&amp;gt;
          &amp;lt;button onClick={() =&amp;gt; pricesCheck(20)}&amp;gt;$20&amp;lt;/button&amp;gt;
          &amp;lt;button onClick={() =&amp;gt; pricesCheck(300)}&amp;gt;$300&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="items-con"&amp;gt;
        {items.map((item) =&amp;gt; {
          return (
            &amp;lt;div className="menu-item-con" key={item.id}&amp;gt;
              &amp;lt;img src={item.image} alt="" /&amp;gt;
              &amp;lt;div className="item-name-price-con"&amp;gt;
                &amp;lt;p className="food-title"&amp;gt;{item.name}&amp;lt;/p&amp;gt;
                &amp;lt;p&amp;gt;${item.price}&amp;lt;/p&amp;gt;
              &amp;lt;/div&amp;gt;
              &amp;lt;p&amp;gt;
                Lorem ipsum, dolor sit amet consectetur adipisicing elit.
                Provident eveniet suscipit atque eius ab sunt cum perspiciatis
                harum laborum natus?
              &amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
          );
        })}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Furthermore, you can also improve on this logic or also include categories so that you better understand the concept of filter method in JavaScript.&lt;/p&gt;

&lt;p&gt;Now you have seen how easy it is to create a very nice filtering functionality with React js and css. This example is beginner friendly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Filtering functionality is very important and nice to be in your application. It enables users to find what they want easily.&lt;br&gt;
The JavaScript filter method returns list of items that matches a specific logic assigned to it.&lt;/p&gt;

&lt;p&gt;Now, i believe that you can easily implement this amazing functionality to your applications to foster good user experience.&lt;br&gt;
Happy coding &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Portle vs Madcap Flare</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Thu, 14 Dec 2023 11:01:45 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/portle-vs-madcap-flare-53jk</link>
      <guid>https://forem.com/ewenikeemmanue4/portle-vs-madcap-flare-53jk</guid>
      <description>&lt;p&gt;Effective documentation is very crucial to the success of software development and product management. Documentation  facilitates swift onboarding, promotes collaboration, and serves as a crucial resource for troubleshooting and debugging. Without effective documentation,organisations will find it difficult to sell their services like APIs. It will be very difficult for team members to collaborate when  there is no effective documentation.&lt;/p&gt;

&lt;p&gt;As a technical writer, you need a very good and efficient documentation tool that can help you convey your information to your audience. A tool that will allow you to express yourself effectively by including code snippets, links, images etc.&lt;/p&gt;

&lt;p&gt;In this article, we will be discussing two amazing documentation tools that will help you to write effective documentation. We will be explaining some of their amazing feature that will help you in writing efficient documentation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Portle&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Madcap Flare&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Portle&lt;/strong&gt;: Portle is an amazing documentation tool that helps you (or your team) as a technical writer to write efficient documentations easy and fast. Portle is  a solution crafted to streamline the creation of user-facing documentation, by offering a simplified approach to documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features of Portle&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ability to invite team members&lt;/li&gt;
&lt;li&gt;Ability to add custome domain&lt;/li&gt;
&lt;li&gt;Release notes&lt;/li&gt;
&lt;li&gt;Versioning&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ability to invite team members&lt;/strong&gt; : Efficient documentation can be a very duanting task, which requires expertise and effort. Portle has an amazing feature that allows you to invite your team members to help you out or to work together. Imagine having a new junior staff in your team, it will be some how difficult for the staff to navigate the world of effective documentation. But with Portle, you can easily take the staff by the hand and teach him how to write amazing documentations by helping you out in the little ways he can.&lt;/p&gt;

&lt;p&gt;The ability to add team members to your Portle account can be very helpful. It will enable effective scrutinization, collabration amongst writers, which will enable them to write effective documentation that will be beneficial to the targeted audience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to add a team member&lt;/strong&gt;: Head over to &lt;a href="https://app.portle.io/" rel="noopener noreferrer"&gt;Portle&lt;/a&gt; (sign up if you have not), go to the settings. You will see 4 tabs namely domain, Plans and billing, user management account management. Select the user management, you will see an interface that will enable you to invite a team memeber by their emails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ftovmgims7erd8ygt3z2m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ftovmgims7erd8ygt3z2m.png" alt="Portle" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ability to add custome domain&lt;/strong&gt;: Portle has another powerful feaure that makes documentation an amazing experience. The ability to add custome domain for your documentation is an awesome experience. For instance, your company is hosting an event like an hackathon, you can easily write down the instructions for the participants to follow. With Portle, you create a dedicated portal at hackathon.yourdomain.com, offering clear and accessible documentation to participants during the event.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to add custome domain in Portle&lt;/strong&gt;: Head over to &lt;a href="https://app.portle.io/" rel="noopener noreferrer"&gt;Portle&lt;/a&gt; (sign up if you have not), go to the settings. You will see 4 tabs namely domain, Plans and billing, user management account management. Select the domain tab, you can see a button that says connect new domain. Click on it and upload the necessary informations to enjoy this feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Foxa5xd5snteo58upvriu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Foxa5xd5snteo58upvriu.png" alt="Portle" width="800" height="410"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzeyivn17lmtz3fr5qe8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzeyivn17lmtz3fr5qe8g.png" alt="Portle" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Release notes&lt;/strong&gt;: Still working on it&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Versioning&lt;/strong&gt;: Still working on it &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Madcap Flare&lt;/strong&gt;: Madcap flare is also an amazing tool that has been around for decades. This tool helps you to create, manage and publish content for your audience. It enables you to write effective documentation easily and fast.&lt;/p&gt;

&lt;p&gt;Madcap flare has awesome and amazing features which can help you in your technical documentation. Here are some of the amazing features Madcap flare has to offer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features of Madcap flare&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Single-Source Authoring&lt;br&gt;
2.Responsive Design&lt;br&gt;
3.Multilingual Support&lt;br&gt;
4.Importation of different file formats&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single-source authoring&lt;/strong&gt; : Madcap flare has a feature that allows you as a technical writer to create content in a single-source format. This will enable you to write and maintain content in one location and then publish it in multiple formats like PDF etc.&lt;/p&gt;

&lt;p&gt;As a technical writer, you might want your documentation to be accessible in many format. MadCap flare can help you to write the documentation once and publish it to both the web and the printer, ensuring consistency which will  save you lots of time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Responsive design&lt;/strong&gt;: As a technical writer, your main goal should be for your documentation to be accessible for your audience to consume. Nowadays, people use different kinds devices with different screen sizes. Having a documentation that can fit in any screen size will be a nice experience for your audience. Madcap flare allows you to write responsive documentation that can adapt to different screen sizes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fql4a9zjvuezayk2d6mfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fql4a9zjvuezayk2d6mfx.png" alt="Madcap flare" width="800" height="444"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multilingual Support&lt;/strong&gt;: Madcap flare has a feature that enables you to write, manage and publish documents in multiple languages. A large number of people do not speak nor understand English, as a technical writer, reaching a wide range of your targeted audience in their different languages will make the documentation so helpful to them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fa726hxu06f2yavnwkvis.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fa726hxu06f2yavnwkvis.png" alt="Madcap flare" width="715" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Importation of different file formats&lt;/strong&gt;: The ability to import different file formats can really help you to write effective documentation as a technical writer. Madcap flare has an amazing feature that enables you to import different kinds of file formats.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fezfp8tm8or85zzekpkz0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fezfp8tm8or85zzekpkz0.png" alt="Madcap flare" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison&lt;/strong&gt;&lt;br&gt;
Portle and Madcap flare are two amazing documentation tools, that have features that can help you write effective and efficient documentation easily. However, just like every other softwares out there, they have their pros and cons.&lt;/p&gt;

&lt;p&gt;Portle is a powerful modern  documentation tool that will help you to write efficient documentation. As a modern day tool, it might not have the features that Madcap flare currently have, but you can get your work done with it. It also has a very easy to understand user interface and affordable pricing.&lt;/p&gt;

&lt;p&gt;Madcap flare is an amazing documentation tool that has been around for a long time, it has lots of amazing features that can help you write documentations. One of the downsides of Madcap flare is that the user interface might not be easy for a new user to understand it. Because of it`s lots of features, Madcap flare costs more than Portle. Most of the features might not be used all the time in your documentation.&lt;/p&gt;

&lt;p&gt;The two tools are amazing, you just have to choose the one that is good for you and your team. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The importance of effective documentation can never be neglected, poor documentation can lead to loss of potential costumers. It will make your product or services hard to use by your costumers.&lt;/p&gt;

&lt;p&gt;Efficient documentation can bring about more revenue, clear communication between you and your targeted audience, effective collaboration amongst your team members and good time management.&lt;/p&gt;

&lt;p&gt;We have explored two amazing documentation tools that can help us write efficient documentation. Portle and Madcap flare are amazing tools that has their pros and cons. But can help us achieve efficient documentation. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Next js Routing</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Tue, 28 Nov 2023 07:30:35 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/next-js-routing-1f7a</link>
      <guid>https://forem.com/ewenikeemmanue4/next-js-routing-1f7a</guid>
      <description>&lt;p&gt;Next js is a framework that has revolutionized the way we developers build websites and web applications. It has lots of amazing tools that are so helpful for your web application. Next js has amazing features like server-side rendering, automatic code splitting, client-side routing, optimized SEO and other amazing features.&lt;/p&gt;

&lt;p&gt;These features has attracted lots of developers and companies to use Next js. &lt;/p&gt;

&lt;p&gt;Next js has an in-built routing system that makes it a nice framework, unlike React js, that uses third party libraries for it`s routing.&lt;/p&gt;

&lt;p&gt;In this article, we will discuss how to create a navigation bar in Next js, exploring the in-built Next js routing system. We will also discuss about the importance of using Next js. Furthermore, We will also compare Next js with it`s cousin React js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites you need to understand this article&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic understanding of HTML.&lt;/li&gt;
&lt;li&gt;Basic understanding of CSS.&lt;/li&gt;
&lt;li&gt;Basic understanding of JavaScript.&lt;/li&gt;
&lt;li&gt;Basic understanding of React js.&lt;/li&gt;
&lt;li&gt;You must have Node js installed on your computer&lt;/li&gt;
&lt;li&gt;And finally, a web browser like Google Chrome.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is a framework&lt;/strong&gt;&lt;br&gt;
A framework is a pre-built, standardized collection of tools, libraries and best practices that helps software developers to build good user interface. Furthermore, frameworks also makes development of software much faster and easier for developers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Next js&lt;/strong&gt;&lt;br&gt;
Next js is an awesome framework built by a company called &lt;a href="https://vercel.com/" rel="noopener noreferrer"&gt;vercel&lt;/a&gt;, this framework was built with some React js features which makes it easier for front-end developers that uses React js to quickly use it too. However, even with close similarities between React js and Next js, Next js has a very different routing or navigation system with React js, which makes it look very new to developers who has experience in React js.&lt;/p&gt;

&lt;p&gt;Next js uses a file-system based router where folders are used to define routes. What does that mean, it simply means that Next js creates routing based on the file structure of your application.&lt;br&gt;
Each component you want to create, you will create a folder for each of the components, these folders will have a file that must be &lt;code&gt;page.js&lt;/code&gt; inside them. This &lt;code&gt;page.js&lt;/code&gt; file in each folder, is where you will write your codes for each component you want your users to see.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
You can use any extension for the page file, you can use &lt;code&gt;.js, .jsx and .ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvuf3vaxcfq2hoa7199gj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvuf3vaxcfq2hoa7199gj.png" alt="Next js routing system" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see here, all of the folders has &lt;code&gt;page.js&lt;/code&gt; file where the components for each folder is written. If a user wants to navigate to our dashboard, all they need to do is to use this path /dashboard and they will see our dashboard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; All of your component folders will be in the app folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let`s code&lt;/strong&gt;&lt;br&gt;
Create a new folder in your favorite code editor (I will be using Visual Studio Code), head over to your terminal and run this command &lt;code&gt;npx create-next-app@latest&lt;/code&gt; to create Next js inside that folder. Make sure you end the command with &lt;code&gt;./&lt;/code&gt; with a little space in between them like this &lt;code&gt;npx create-next-app@latest ./&lt;/code&gt;, this will create Next js in that current folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fj6h5kjya9jfxrtnbbsyf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fj6h5kjya9jfxrtnbbsyf.png" alt="Next js" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you run that command, you will get this question press enter to continue the installation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fxg248ziyea6t0x9jwnos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fxg248ziyea6t0x9jwnos.png" alt="Next js installation" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, you will also see these questions, make sure you select the answers  like I just did in this image. To select the answers, you have to use your (left and right) arrows accordingly, then press enter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwmud0f6xnqyi9f8elxlo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwmud0f6xnqyi9f8elxlo.png" alt="Next js routing system" width="800" height="430"&gt;&lt;/a&gt;&lt;br&gt;
After the installation process, you will have a screen like this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ftzfyr998o1na90c83vrn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ftzfyr998o1na90c83vrn.png" alt="Next js routing" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will create 3 folders inside our app folder, each of these folders will have a &lt;code&gt;page.js&lt;/code&gt; file where we will be writing the components for each folder. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8l2xgju8t4o9s97htaeo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8l2xgju8t4o9s97htaeo.png" alt="Next js routing" width="309" height="866"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have created our folders and pages, let`s start building each component inside the pages of each folders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client"
const Analytics = () =&amp;gt; {
    return ( 
        &amp;lt;section&amp;gt;
            &amp;lt;h1&amp;gt;This is the analytics page&amp;lt;/h1&amp;gt;
        &amp;lt;/section&amp;gt;
     );
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client"
const dashboard = () =&amp;gt; {
    return ( 
        &amp;lt;section&amp;gt;
        &amp;lt;h1&amp;gt;This is the dashboard&amp;lt;/h1&amp;gt;
        &amp;lt;/section&amp;gt;
     );
}

export default dashboard;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client"
const Settings = () =&amp;gt; {
    return ( 
        &amp;lt;section&amp;gt;
            &amp;lt;h1&amp;gt;This is the settings page&amp;lt;/h1&amp;gt;
        &amp;lt;/section&amp;gt;
     );
}

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

&lt;/div&gt;



&lt;p&gt;Let us view what we have been creating since, head over to your terminal and run this command &lt;code&gt;npm run dev&lt;/code&gt; to view your work on the browser. Once the command has finish running, you have to go to your browser and paste this url &lt;code&gt;http://localhost:3000&lt;/code&gt; to view what we have been building.&lt;br&gt;
You must see something like this on your browser&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5y2ukday66qxktkvc3d7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5y2ukday66qxktkvc3d7.png" alt="a Next js index page" width="800" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go ahead and change the url of your application by adding a slash, and then, the name of the folder you want to see. Like this &lt;code&gt;/settings&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; This is case sensitve, make sure that it is the exact folder name that you type, if not, you will get a 404 error message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Flnz81dozyqtc1f3nw31j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Flnz81dozyqtc1f3nw31j.png" alt="Next js routing" width="800" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now i know you will be wondering, "will my users have to type the page they want to see manually?" No they will not, you will have to create another folder (your navigation) with a page file, like other folders. Inside that page, create a navigation links and import the navigation component inside the &lt;code&gt;layout.js&lt;/code&gt; file. Like this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ftgstqjoqw7kgbsezbq19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ftgstqjoqw7kgbsezbq19.png" alt="Next js routing" width="800" height="431"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Navigation&lt;/strong&gt; The navigation consists of navigation links, we make use of the in-built link in Next js and use that to replace the normal anchor tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client"
import Link from 'next/link'
const Navigation = () =&amp;gt; {
    return ( 
        &amp;lt;main&amp;gt;
            &amp;lt;nav className='bg-red-500'&amp;gt;
        &amp;lt;ul className='flex '&amp;gt;
          &amp;lt;li className='p-3 cursor-pointer'&amp;gt;&amp;lt;Link href="/"&amp;gt;Home&amp;lt;/Link&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-3 cursor-pointer'&amp;gt;&amp;lt;Link href="/analytics"&amp;gt;Analytics&amp;lt;/Link&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-3 cursor-pointer'&amp;gt;&amp;lt;Link href="/dashboard"&amp;gt;Dashboard&amp;lt;/Link&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-3 cursor-pointer'&amp;gt;&amp;lt;Link href="/settings"&amp;gt;Settings&amp;lt;/Link&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/nav&amp;gt;
        &amp;lt;/main&amp;gt;
     );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fz2otz9a6s129wp9frwi8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fz2otz9a6s129wp9frwi8.png" alt="Next js routing" width="800" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layout page&lt;/strong&gt; This page is where you import any component you want to seen across all components, like your navigation  and footer components.&lt;/p&gt;

&lt;p&gt;You are supposed to have something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7avigjjw1c7bt5hvl40r.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7avigjjw1c7bt5hvl40r.gif" alt="Next js routing" width="348" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The home page here is that &lt;code&gt;page.js&lt;/code&gt; file inside the app folder, that file carrys the template code you will see when you run &lt;code&gt;npm run dev&lt;/code&gt; command in your terminal. You have to clear those template codes up and create what you want as your home page.&lt;br&gt;
Here is mine&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frclwxc3e1bddc6t82x30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frclwxc3e1bddc6t82x30.png" alt="Next js routing" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Next js uses file based routing system that enables developers to build fast and easy to implement navigations based on their file structure. It does not need an additional library for that, which is very cool.&lt;/p&gt;

&lt;p&gt;Now you have seen how easy it is to implement navigation in Next js. Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>nextjs</category>
      <category>react</category>
    </item>
    <item>
      <title>Demystifying the Ternary Operator in JavaScript</title>
      <dc:creator>Ewenike Chukwuemeka Emmanuel👨‍💻</dc:creator>
      <pubDate>Wed, 27 Sep 2023 16:37:55 +0000</pubDate>
      <link>https://forem.com/ewenikeemmanue4/demystifying-the-ternary-operator-in-javascript-2d2f</link>
      <guid>https://forem.com/ewenikeemmanue4/demystifying-the-ternary-operator-in-javascript-2d2f</guid>
      <description>&lt;p&gt;Have you ever wondered if we can remove that curly brackets that comes with &lt;strong&gt;if and else&lt;/strong&gt; statement? Or you wish if you can just use it inside your jsx (if you use React js) without writing any function?&lt;/p&gt;

&lt;p&gt;Ternary operator will help you achieve the same result, you can write simple conditional logic in one line, yes one line 😊. Ternary operator will also help you to write conditional codes in your jsx. Ternary operator will help you write clean and efficient codes as a developer.&lt;/p&gt;

&lt;p&gt;In this article, we will understand what is ternary operator, it`s syntax and how to use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites you need to understand this article&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Basic understanding of HTML,CSS and JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic knowledge of any JavaScript framework like React js&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A web browser like Google Chrome&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is Ternary Operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ternary operator is a concise conditional operator in Javascript, that allows developers to write conditional statements in a single line of code. Ternary operator makes developers` code more readable and clean.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ternary operator is made up of the condition, the logic that will be implemented if the condition is true, then the logic that will be implemented if the logic is false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;condition ? expression_if_true : expression_if_false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

class MyComponent extends React.Component {
  render() {
    const isLoggedIn = true;


    return (
      &amp;lt;div&amp;gt;
        &amp;lt;p&amp;gt;{isLoggedIn? "We have a user" : "No user"}&amp;lt;/p&amp;gt; 
      &amp;lt;/div&amp;gt;
    );
  }
}

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

&lt;/div&gt;



&lt;p&gt;From this simple code, I am checking if the variable isLoggin is true or false, if it`s true our p tag will display "We have a user", like this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fnvzj41ize6qou6a3jstc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fnvzj41ize6qou6a3jstc.png" alt="Ternary operator in demonstration" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the variable is false then our p tag will display "No user", it`s very simple.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fnzm1uh9utvizj3teojer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fnzm1uh9utvizj3teojer.png" alt="Ternary operator in demonstration" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is a more complex example&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 } from "react";
import products from "./DemoCartMenuData";
import { useContext } from "react";
import { Link } from "react-router-dom";
import  {CartContext}  from './Context';
import StarBorderIcon from '@mui/icons-material/StarBorder';

const DemoCartMenu = () =&amp;gt; {

    const {addToCart}   = useContext(CartContext);
    const {cartItems} = useContext(CartContext);

    const {errorMessage}= useContext(CartContext);

    const [items, setItems]= useState(products);

    const cheapItemFisrtFunction=(price)=&amp;gt;{
        const cheapItem15 = products.filter((itemP)=&amp;gt; itemP.price &amp;lt;= price)
        setItems(cheapItem15)
    }
    const cheapItemSecondFunction = (price)=&amp;gt;{
        const cheapItem20 = products.filter((itemP)=&amp;gt;itemP.price &amp;gt;= price)
        setItems(cheapItem20)
    }
    const cheapItemThirdFunction = (price)=&amp;gt;{
        const cheapItem30 = products.filter((itemP)=&amp;gt; itemP.price &amp;gt;= price)
        setItems(cheapItem30);
    }

    const cheapItemFourtFunction= (price)=&amp;gt;{
        const cheapItem40 = products.filter((itemP)=&amp;gt; itemP.price &amp;gt;= price)
        setItems(cheapItem40)
    }
    const fullProducts = (prod)=&amp;gt;{
        if(prod === "all"){
            setItems(products)
        }
    }

    const changeBtnBg = (e)=&amp;gt;{

    const buttons = document.querySelectorAll('.filter-btn');

    buttons.forEach((button) =&amp;gt; {
        button.classList.remove("active");
    });

    e.target.classList.add("active");
    }

    return ( 
        &amp;lt;section className="product-section"&amp;gt;
            &amp;lt;h3&amp;gt;Filter products by price&amp;lt;/h3&amp;gt;
            &amp;lt;div className="filter-btn-con" onClick={changeBtnBg}&amp;gt;
            &amp;lt;button onClick={()=&amp;gt;cheapItemFisrtFunction(15)} className="filter-btn"&amp;gt;💲15 below&amp;lt;/button&amp;gt;
            &amp;lt;button onClick={()=&amp;gt;cheapItemSecondFunction(20)} className="filter-btn"&amp;gt; 💲20 and above &amp;lt;/button&amp;gt;
            &amp;lt;button onClick={()=&amp;gt;cheapItemThirdFunction(30)} className="filter-btn"&amp;gt; 💲30 and above &amp;lt;/button&amp;gt;
            &amp;lt;button onClick={()=&amp;gt;cheapItemFourtFunction(40)} className="filter-btn"&amp;gt; 💲40 and above &amp;lt;/button&amp;gt;

            &amp;lt;button onClick={()=&amp;gt; fullProducts("all")} className="filter-btn"&amp;gt;All&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;


            &amp;lt;div className="items-grid-con"&amp;gt;
            {
                items.map((item)=&amp;gt;{
                    return(
                        &amp;lt;div className="item-con"&amp;gt;
                            &amp;lt;Link to={`/ItemDetails/${item.id}`}&amp;gt;
                            &amp;lt;div className="img-con"&amp;gt;
                                &amp;lt;img src={item.img} alt={item.name} /&amp;gt;
                            &amp;lt;/div&amp;gt;
                            &amp;lt;/Link&amp;gt;
                            &amp;lt;div className="item-details-con"&amp;gt;
                            &amp;lt;div className="item-price-name-con"&amp;gt;
                                &amp;lt;p&amp;gt;{item.name}&amp;lt;/p&amp;gt;
                                &amp;lt;p&amp;gt; 💲{item.price}&amp;lt;/p&amp;gt;
                            &amp;lt;/div&amp;gt;
                            &amp;lt;div className="item-rating-con"&amp;gt;
                            &amp;lt;StarBorderIcon className="rating"/&amp;gt; &amp;lt;StarBorderIcon className="rating"/&amp;gt;&amp;lt;StarBorderIcon className="rating"/&amp;gt;&amp;lt;StarBorderIcon className="rating"/&amp;gt;

                            &amp;lt;/div&amp;gt;

                            //this code here
                            &amp;lt;button onClick={()=&amp;gt; addToCart(item)}&amp;gt;
                                { cartItems.find((tem)=&amp;gt; tem.id===item.id)?"Item is in cart":"Add to cart"}&amp;lt;/button&amp;gt;
                            &amp;lt;/div&amp;gt;




                        &amp;lt;/div&amp;gt;
                    )
                })
            }
            &amp;lt;/div&amp;gt;

        &amp;lt;/section&amp;gt;
     );
}

export default DemoCartMenu;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you check the code above, you will see this small piece of code&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;button onClick={()=&amp;gt; addToCart(item)}&amp;gt;{ cartItems.find((tem)=&amp;gt; tem.id===item.id)?"Item is in cart":"Add to cart"}&amp;lt;/button&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code checks whether any of the items I am rendering has been added to the cart or not. If the id of the products matches with any id of an item in the cart, the button will display "Item is in cart" if not, the button will display "Add to cart". Click this link to watch a simple demonstration of what I am trying to explain &lt;a href="https://screenrec.com/share/Hn6Zbj1wqY" rel="noopener noreferrer"&gt;Link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; This is one of my old e-commerce project.&lt;/p&gt;

&lt;p&gt;Now that you have understood what ternary operator is, how to use it, when to use it and why you should use it. You can now go ahead and build amazing applications with your newly acquired super power 😊.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Ternary operator is a concise conditional operator in JavaScript, that enables developers to write clean and readable codes. It only takes one line, it also allows you to implement simple logic in your jsx.&lt;/p&gt;

&lt;p&gt;I believe you now understand what a ternary operator is and why you should use it.&lt;/p&gt;

&lt;p&gt;Please if you have any question let me know in the comment section I will reply to your questions. Please don`t forget to like this article for other developers to see it. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
    </item>
  </channel>
</rss>
