<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Bilson</title>
    <description>The latest articles on DEV Community by David Bilson (@david_bilsonn).</description>
    <link>https://dev.to/david_bilsonn</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%2F1027690%2F843b1845-9262-4d78-a80e-e958888cab6b.jpg</url>
      <title>DEV Community: David Bilson</title>
      <link>https://dev.to/david_bilsonn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/david_bilsonn"/>
    <language>en</language>
    <item>
      <title>🔐 WTF is JWT? And Why Your Frontend Should Care</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Fri, 18 Apr 2025 16:35:14 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/wtf-is-jwt-and-why-your-frontend-should-care-4iji</link>
      <guid>https://dev.to/david_bilsonn/wtf-is-jwt-and-why-your-frontend-should-care-4iji</guid>
      <description>&lt;p&gt;This flew over my head since 2022 — you and every dev before their JWT awakening.&lt;/p&gt;




&lt;p&gt;You're not alone if you've ever felt confused about JWTs (JSON Web Tokens). But today, let’s break it down in plain English, with enough sauce to make it stick.&lt;/p&gt;

&lt;h4&gt;
  
  
  🚀 What the Heck is JWT?
&lt;/h4&gt;

&lt;p&gt;JWT = a secure way to send user data from server → client.&lt;br&gt;
But not just any data — usually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": "user_id_123",
  "email": "david@email.com",
  "role": "admin"
}

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

&lt;/div&gt;



&lt;p&gt;The server takes this, signs it, and sends it back to the frontend as a token. That token is your magic key to access protected routes.&lt;/p&gt;




&lt;h4&gt;
  
  
  🔄 JWT Flow in the Real World
&lt;/h4&gt;

&lt;p&gt;Here’s the flow that makes you look like a senior dev:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User logs in → Server sends a JWT back.&lt;/li&gt;
&lt;li&gt;Frontend stores the token (usually in localStorage or a secure cookie).&lt;/li&gt;
&lt;li&gt;On every request, frontend sends it back to the server via the Authorization header.&lt;/li&gt;
&lt;li&gt;Backend checks it, confirms it’s not tampered with, and knows who’s talking.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  🧠 What Does the Frontend Do With It?
&lt;/h4&gt;

&lt;p&gt;🔥 This is where your aha moment lives.&lt;/p&gt;

&lt;p&gt;JWT on the frontend = no need to persist user manually.&lt;/p&gt;

&lt;p&gt;Instead of saving user data in Zustand or Redux, just:&lt;/p&gt;

&lt;p&gt;Store the token in localStorage.&lt;/p&gt;

&lt;p&gt;Decode it when needed to get stuff like userId, email, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install jwt-decode
&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;import jwtDecode from "jwt-decode";

const token = localStorage.getItem("token");

if (token) {
  const decoded = jwtDecode(token);
  console.log(decoded.id); // user ID from token payload
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes — it’s that simple. You don’t even verify it on the frontend (that’s backend’s job).&lt;/p&gt;




&lt;h4&gt;
  
  
  ⚠️ Zustand vs JWT — Who Wins?
&lt;/h4&gt;

&lt;p&gt;Zustand is 🔥 for managing state in the moment, but it doesn’t persist user sessions on its own.&lt;/p&gt;

&lt;p&gt;Instead:&lt;/p&gt;

&lt;p&gt;Use JWT to persist auth state&lt;/p&gt;

&lt;p&gt;Optionally: Decode and drop relevant info into Zustand for quick access.&lt;/p&gt;




&lt;h4&gt;
  
  
  💡 TL;DR
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;JWT = user's data + secret sauce (signature)&lt;/li&gt;
&lt;li&gt;Sent from backend → stored on frontend&lt;/li&gt;
&lt;li&gt;Frontend decodes it to know the logged-in user&lt;/li&gt;
&lt;li&gt;No need to save full user info manually&lt;/li&gt;
&lt;li&gt;Send it back to the server with every request as proof of identity&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  🔓 BONUS: Pro Tips
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Don’t trust the token blindly — always verify on the backend.&lt;/li&gt;
&lt;li&gt;Don’t store sensitive info inside (like passwords).&lt;/li&gt;
&lt;li&gt;Use httpOnly cookies instead of localStorage if you're paranoid about security.&lt;/li&gt;
&lt;li&gt;Use jwt-decode on the frontend — don’t try to decode manually, your brain deserves better.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  👑 Final Words
&lt;/h4&gt;

&lt;p&gt;JWT is not magic. It’s just a clever way to carry a user’s identity like a digital passport. Once you get the hang of it, everything else about authentication starts to click.&lt;/p&gt;

&lt;p&gt;Now go flex that knowledge in your code — or better yet, drop it on X like:&lt;/p&gt;

&lt;p&gt;“I just decode the JWT on load and store the user’s ID in Zustand — keeps it clean.”&lt;/p&gt;

&lt;p&gt;Boom! Instant clout!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>jwt</category>
      <category>frontend</category>
      <category>backenddevelopment</category>
    </item>
    <item>
      <title>How to Fix Vercel 404 error: Child URL Path Issues</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Wed, 11 Oct 2023 10:00:04 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/how-to-fix-vercel-404-error-child-url-path-issues-n0o</link>
      <guid>https://dev.to/david_bilsonn/how-to-fix-vercel-404-error-child-url-path-issues-n0o</guid>
      <description>&lt;p&gt;Vercel is a popular hosting platform for front-end applications, offering various deployment and hosting features. Deploying a React app to Vercel is a straightforward process, but it can become problematic when you need to handle redirects from child paths to the root. &lt;br&gt;
When deploying a React app, you might encounter a situation where your child paths aren't automatically redirected to the root, causing unexpected behavior in your application. After having the page deployed, for example, &lt;code&gt;https://yourwebsite.vercel.app&lt;/code&gt;, this path loads successfully, right? But once you navigate to a different route on the page and try to refresh, you'll usually see a 404 error like the one below.&lt;/p&gt;

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

&lt;p&gt;There are cases whereby you would want to show someone a specific page on your react app, and you would want to give them the exact URL to that page, for example, &lt;code&gt;https://yourwebsite.vercel.app/contact-page&lt;/code&gt;. If the person loads the page, they will get a 404 error simply because Vercel fails to load the child path from the root.&lt;/p&gt;

&lt;p&gt;I assume you already have your app built and deployed on Vercel? If you haven't, please do so. Let's say you already have a React app with multiple routes, and your app is hosted on Vercel. When you visit a child path of your app, such as &lt;code&gt;https://yourapp.vercel.app/child&lt;/code&gt;, you might expect it to redirect to the root path &lt;code&gt;(https://yourapp.vercel.app/)&lt;/code&gt;, but it doesn't happen by default. This can lead to issues like broken links, incorrect rendering, and a poor user experience.&lt;/p&gt;

&lt;p&gt;To solve this problem, you can use Vercel's "rewrites" feature. "rewrites" allows you to configure how requests are handled, including URL redirection. In this case, you want to redirect all child paths to the root path.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;vercel.json&lt;/code&gt; file within the root folder of your project.&lt;/p&gt;

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

&lt;p&gt;Then paste the code below within the json file:&lt;/p&gt;

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

{
  "rewrites": [
    { "source": "/(.*)", "destination": "/" }
  ]
}


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;"rewrites"&lt;/code&gt; specifies the rules for URL rewrites.&lt;br&gt;
&lt;code&gt;{ "source": "/(.*)", "destination": "/" }&lt;/code&gt; tells Vercel that for any URL path that matches /(.*) (essentially any path), redirect the request to the root path (/).&lt;br&gt;
Ensure you push these new changes to update your repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By adding this simple configuration in the vercel.json file, you can resolve this issue. With this configuration in place, your React app will redirect child paths to the root path, ensuring that all your routes work as intended.&lt;/p&gt;

</description>
      <category>react</category>
      <category>vercel</category>
      <category>javascript</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>How to Setup Tailwind CSS in React JS with VS Code</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Sat, 23 Sep 2023 20:11:32 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/how-to-setup-tailwind-css-in-react-js-with-vs-code-59p4</link>
      <guid>https://dev.to/david_bilsonn/how-to-setup-tailwind-css-in-react-js-with-vs-code-59p4</guid>
      <description>&lt;p&gt;Tailwind CSS has gained popularity among front-end developers due to its utility-first approach and flexibility. It allows developers to build modern and responsive user interfaces with ease and speed.&lt;/p&gt;

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

&lt;p&gt;When combined with React JS, Tailwind CSS becomes an even more potent tool for creating visually appealing and efficient web applications.&lt;br&gt;
This tutorial will guide you through the step-by-step process of setting up Tailwind CSS in a React project using Visual Studio Code (VS Code). By the end of this guide, you will have a fully functional React application with Tailwind CSS integrated and ready for deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before we begin, ensure that you have the following installed on your system:&lt;/p&gt;

&lt;h4&gt;
  
  
  Node.js and npm:
&lt;/h4&gt;

&lt;p&gt;To set up a React application, you need Node.js and npm installed on your computer. Download and install the latest LTS version of NodeJS from the &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;official Node.js website&lt;/a&gt;.&lt;br&gt;
To download the latest version of npm, on the command line, run the following command:&lt;/p&gt;

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

npm install -g npm


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Visual Studio Code (VS Code):
&lt;/h4&gt;

&lt;p&gt;VS Code is a popular code editor that provides a seamless development experience for developers. It is the most preferred IDE if you want to develop your application with the best experience. You can download it for free from the &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;official VS Code website&lt;/a&gt; and install it on your computer.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1:
&lt;/h2&gt;
&lt;h4&gt;
  
  
  Create a New React Application Using Vite
&lt;/h4&gt;

&lt;p&gt;Vite is a better alternative to CRA (create-react-app). It provides a faster and leaner development experience for modern web projects built with React, Angular, or Vue. Vite is popularly known for speed, efficiency, lightweight, and simplicity. &lt;a href="https://vitejs.dev/guide/" rel="noopener noreferrer"&gt;Learn more about Vite here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To install a React application using Vite, open your terminal or command prompt and navigate to the root directory where you want to install the React project. &lt;br&gt;
Then, run the following command to create a new application&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm create vite@latest


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

&lt;/div&gt;

&lt;p&gt;You will be asked in the terminal to write the name of the project. For the sake of this tutorial, I will be going with "tailwind-setup" as the project name.&lt;br&gt;
Thereafter, you will be asked to select a framework to work with. Select React.&lt;/p&gt;

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

&lt;p&gt;You will be asked to select a variant. Select JavaScript.&lt;/p&gt;

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

&lt;p&gt;Afterward, navigate to the project directory using the command &lt;code&gt;cd project-name&lt;/code&gt;. Since the name of this project is tailwind-setup, we will enter the project directory and execute the following commands.&lt;/p&gt;

&lt;p&gt;Enter the project directory&lt;/p&gt;

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

 cd tailwind-setup


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

&lt;/div&gt;

&lt;p&gt;Run npm install to install the necessary packages and dependencies for the React project.&lt;/p&gt;

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

 npm install


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

&lt;/div&gt;

&lt;p&gt;After installing the packages and dependencies, you need to open VS Code editor with the current directory. To do that, run the command below &lt;/p&gt;

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

 code .


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

&lt;/div&gt;

&lt;p&gt;A new window will be opened up and you will be able to access the project files from the side bar (also known as the Explorer). &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Install Tailwind CSS
&lt;/h4&gt;

&lt;p&gt;When you want to install Tailwind in React, you have to remember that you installed this React project with Vite. To avoid dependency issues, you must install Tailwind for Vite React. You will find the installation guide on &lt;a href="https://tailwindcss.com/docs/installation" rel="noopener noreferrer"&gt;Tailwind Docs&lt;/a&gt;. The first installation guide &lt;strong&gt;(Tailwind CLI)&lt;/strong&gt; on the docs points to general installation. Click on &lt;strong&gt;(Framework Guides)&lt;/strong&gt; &lt;/p&gt;

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

&lt;p&gt;This will show you a list of frameworks to pick from. Select Vite.&lt;/p&gt;

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

&lt;p&gt;You will be brought to this page&lt;/p&gt;

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

&lt;p&gt;You already have React installed using Vite, so we just have to install Tailwindcss and its peer dependencies with the command:&lt;/p&gt;

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

npm install -D tailwindcss postcss autoprefixer


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

&lt;/div&gt;

&lt;p&gt;Then generate your tailwind.config.js and postcss.config.js files with the command below:&lt;/p&gt;

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

npx tailwindcss init -p


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 3:
&lt;/h2&gt;
&lt;h4&gt;
  
  
  Configure Tailwind CSS
&lt;/h4&gt;

&lt;p&gt;Add the paths to all of your template files in your tailwind.config.js file. You can do that by copying the template available in the config file on the docs. It's also provided below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 4
&lt;/h2&gt;
&lt;h4&gt;
  
  
  Add the Tailwind directives to your index.css file
&lt;/h4&gt;

&lt;p&gt;To import Tailwind CSS into your project. Open the "src/index.css" file, which is the main CSS file for your React application. Remove all the existing code in the file and add the following import statement to include Tailwind CSS:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@tailwind base;
@tailwind components;
@tailwind utilities;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 5
&lt;/h2&gt;
&lt;h4&gt;
  
  
  Run the Development Server
&lt;/h4&gt;

&lt;p&gt;Now that Tailwind CSS is integrated into your React project, it's time to start the development server and see the changes in action.&lt;br&gt;
Run your build process with &lt;code&gt;npm run dev&lt;/code&gt; in the terminal.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm run dev


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

&lt;/div&gt;

&lt;p&gt;This will start the development server, and you can access your React application in the local host server address provided in the terminal: &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Styling components/elements with Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;If you are not a Tailwind expert yet, you can easily look up the class names for any CSS property you need on an element by searching for it on the docs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;

&lt;p&gt;Let us style a h1 element and a paragraph element in the App.jsx file of our React application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the h1 and p element&lt;/li&gt;
&lt;/ul&gt;

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

import React from 'react'

const App = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt; Tailwind Setup &amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;Styling jsx elements&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default App


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

&lt;/div&gt;

&lt;p&gt;To give the h1 text a yellow color, you go on to Tailwind Docs&lt;/p&gt;

&lt;p&gt;Go to the tailwind docs, you will see a search bar on the left side bar on the docs page, search for text color, on the results, click on text color and then go through the lists of colors made available to you to choose, I will go with &lt;code&gt;text-red-600&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;Copy the class name and apply it to the h1 element&lt;/p&gt;

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

&amp;lt;h1 className="text-red-600"&amp;gt;Tailwind Setup&amp;lt;/h1&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;To make the paragraph underlined, search for underline on the docs,&lt;/p&gt;

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

&lt;p&gt;Apply it to the paragraph element:&lt;/p&gt;

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

&amp;lt;p className='underline'&amp;gt;Styling jsx elements&amp;lt;/p&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Elements should be styled according to the design requirements of your project.&lt;/p&gt;

&lt;p&gt;You now have a powerful combination of React's component-based architecture and Tailwind CSS's utility-first approach at your disposal. This combination allows you to create visually appealing and responsive web applications with speed and efficiency.&lt;/p&gt;

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

</description>
      <category>tailwindcss</category>
      <category>css</category>
      <category>react</category>
      <category>vite</category>
    </item>
    <item>
      <title>Learn How to Build Responsive Navigation Bar with HTML, CSS, and JavaScript</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Fri, 30 Jun 2023 11:19:04 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/learn-how-to-build-responsive-navigation-bar-with-html-css-javascript-4g5</link>
      <guid>https://dev.to/david_bilsonn/learn-how-to-build-responsive-navigation-bar-with-html-css-javascript-4g5</guid>
      <description>&lt;p&gt;A responsive navigation bar is essential for any web application, whether you are building static websites using the frontend trio (HTML, CSS, JS) or technologies such as React and Angular for single-page apps, it is crucial to know how to build a well-designed navigation bar.&lt;/p&gt;

&lt;p&gt;This step-by-step tutorial will give you a clean walk-through, and a straightforward approach to building a responsive navigation bar that adapts to different screen sizes and provides a clean browsing experience for your users.&lt;/p&gt;

&lt;p&gt;If you are a beginner, it is important to understand that when building with HTML, it is advisable to avoid using div containers excessively. Instead, you should adopt a semantic approach.&lt;/p&gt;

&lt;p&gt;To ensure clarity, let's break down the entire tutorial into a series of steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 (HTML structure)
&lt;/h2&gt;

&lt;p&gt;Create the complete HTML structure.&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Navigation Bar&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember, all the content of a web page is enclosed within the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; element. Therefore, we will begin by nesting a &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; element within the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; element. This &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; element will be the parent container for the &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 (Create header and nav element)
&lt;/h2&gt;

&lt;p&gt;Create a &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; element within the body and assign it a class name of &lt;strong&gt;"navigation-header"&lt;/strong&gt;. Next, nest a &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; element within the &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;. Inside the &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;, include two &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; containers.&lt;br&gt;
The first div, with a class name of &lt;strong&gt;"logo-container"&lt;/strong&gt;, will contain the logo, while the second div, with a class name of &lt;strong&gt;"navigation-items"&lt;/strong&gt; will contain the navigation items. Also, give the navigation items container an &lt;strong&gt;id&lt;/strong&gt; of &lt;strong&gt;"navigation-items"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Nest &lt;code&gt;&amp;lt;a&amp;gt;&amp;lt;/a&amp;gt;&lt;/code&gt; within the logo container, the content of the anchor tag can either be text or an image, depending on the requirement of your project. &lt;br&gt;
Nest three &lt;code&gt;&amp;lt;a&amp;gt;&amp;lt;/a&amp;gt;&lt;/code&gt; within the navigation items container. The text content of each anchor element will be based on the requirements of your project. For the sake of this tutorial, I will use "About", "Projects", and "Contact Me" as the text contents for each anchor element respectively.&lt;/p&gt;

&lt;p&gt;Lastly, for the HTML part of this tutorial, you will nest another div container within the nav element. This container will host the hamburger icons that will be displayed on smaller screens. Give it a class name of &lt;strong&gt;"hamburger"&lt;/strong&gt;. Then, nest two spans within it. The first span should have an id of &lt;strong&gt;"openHam"&lt;/strong&gt; with a hamburger HTML entity as its text content &lt;code&gt;&amp;amp;#9776;&lt;/code&gt;. The second span should have an id of &lt;strong&gt;"closeHam"&lt;/strong&gt; with a HTML entity &lt;code&gt;&amp;amp;#x2716;&lt;/code&gt; as its text content.&lt;/p&gt;
&lt;h3&gt;
  
  
  Complete HTML Code Snippet
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;header class="navigation-header"&amp;gt;
    &amp;lt;nav&amp;gt;
        &amp;lt;div class="logo-container"&amp;gt;
            &amp;lt;a href="./index.html"&amp;gt;Logo&amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="navigation-items" id="navigation-items"&amp;gt;
            &amp;lt;a href=""&amp;gt;About&amp;lt;/a&amp;gt;
            &amp;lt;a href=""&amp;gt;Projects&amp;lt;/a&amp;gt;
            &amp;lt;a href=""&amp;gt;Contact Me&amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="hamburger"&amp;gt;
            &amp;lt;span id="openHam"&amp;gt;&amp;amp;#9776;&amp;lt;/span&amp;gt;
            &amp;lt;span id="closeHam"&amp;gt;&amp;amp;#x2716;&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/nav&amp;gt;
   &amp;lt;/header&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 3 (Styling with CSS)
&lt;/h2&gt;

&lt;p&gt;Before proceeding to styling the HTML elements in the external CSS file, ensure the CSS file is attached to the HTML file within the head element using the  tag.&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;link rel="stylesheet" href="style.css"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is a common practice in web development to apply a CSS reset or CSS normalization to ensure a consistent starting point for styling across different browsers. By resetting the padding, margin, and box-sizing properties of all elements, as well as the body element, you can avoid any inconsistencies or unexpected default styles that different browsers may apply.&lt;/p&gt;

&lt;h4&gt;
  
  
  - Create a consistent styling foundation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*, body {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CSS snippet above helps to create a more predictable layout and styling behavior across different browsers and devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Style the navigation header
&lt;/h3&gt;

&lt;p&gt;Select the header element using its class name. Since it is the parent container for the &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;, it is going to be the main background, and would have a definite height.&lt;br&gt;
The navigation element within it should be centered on the x-axis and y-axis, therefore, flex properties come into play.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.navigation-header {
  background-color: rgb(73, 51, 153);
  padding: 0 15px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Style the &lt;strong&gt;nav&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Since we are working with only one &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; element, we do not need to give it a class name. Select the nav element using its element name.&lt;br&gt;
If the project you are working requires a uniform width on all parent containers, then you are going to set the max-width of the nav to that required max-width of your project.&lt;/p&gt;

&lt;p&gt;For the sake of this project, we are going to set the max-width to 1200px. To make the container stretch to the full max-width, apply 100% width. This way, the container stretches up to the max-width but won't exceed the maximum width making the container responsive in that process.&lt;br&gt;
There are three child containers within the nav, they need to be on the same plain on the x-axis, therefore, we are going to make use of the flex properties to space out the containers and align them properly using the snippet below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nav {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Style the logo
&lt;/h3&gt;

&lt;p&gt;Select the anchor element within the logo container. Set its text color to &lt;code&gt;ghostwhite&lt;/code&gt;. Remove any underlining or decoration from the text within the &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element. Set the font-weight to bold (700 is the numeric value for bold font-weight). Set the font-size to 26 pixels.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.logo-container &amp;gt; a {
  color: ghostwhite;
  text-decoration: none;
  font-weight: 700;
  font-size: 26px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Style the navigation items
&lt;/h4&gt;

&lt;p&gt;Select the navigation items using its class name. Within the navigation items, we have three navigation links, make them align horizontally using the flex layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.navigation-items {
  display: flex;
  gap: 40px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Style the navigation links
&lt;/h3&gt;

&lt;p&gt;Select the links within the navigation items using the direction child selector. Set the text color to "ghostwhite", remove text decoration, apply a font weight of 500, and set the font size to 16 pixels. Also add a transition for smooth hover effect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.navigation-items &amp;gt; a {
  color: ghostwhite;
  text-decoration: none;
  font-weight: 500;
  font-size: 16px;
  transition: .4s ease-in-out;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add hover effect to navigation links
&lt;/h3&gt;

&lt;p&gt;Simply change the color of the navigation to white, or based on the requirement of your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.navigation-items &amp;gt; a:hover {
  color: white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Style the hamburger
&lt;/h3&gt;

&lt;p&gt;The hamburger has two child elements within it which includes the openHam and the closeHam icons. Here we used HTML entities for the icons, you can import icons from icon libraries such as font awesome, google fonts or iconicon library.&lt;br&gt;
On desktop and laptop screens, we definitely do not want the hamburger icons to show, so we hide them by default, then make them show up on smaller screens using media queries. But we are going to add some other default styling to the hamburger.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hamburger {
  display: none;
  font-size: 20px;
  font-weight: 800;
  color: white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are done with the desktop version of the entire navigation. Now, let's proceed to making it responsive and well designed for the smaller screens using media query.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create a different style for hamburger, and the navigation items on smaller screens using CSS media query
&lt;/h4&gt;

&lt;p&gt;Here, we are going to have a different style from tablet devices with &lt;strong&gt;screen sizes&lt;/strong&gt; from &lt;strong&gt;768px&lt;/strong&gt; below, this would also cover for mobile screens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media screen and (max-width:768px) { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Media query is commonly used for creating responsive designs that adapt to smaller screen sizes, such as tablets or smaller desktop screens.&lt;/p&gt;

&lt;p&gt;In the above code snippet, the styles within the media query will only be applied when the screen width is 768 pixels or smaller. &lt;/p&gt;

&lt;p&gt;Elements are reselected within the curly braces and are styled to fit properly to the current screen size as written in the media query which is 768px in this case.&lt;/p&gt;

&lt;p&gt;The hamburger and the navigation items will be reselected and styled to fit properly for the 768px screens&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media screen and (max-width:768px) {
  .hamburger {
    display: flex;
    cursor: pointer;
  }
  .hamburger #closeHam {
    display: none;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The closeHam icon is hidden and should only display when the navigation menu is displayed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Style the navigation-items within the media query
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.navigation-items {
    display: none;
    flex-direction: column;
    align-items: center;
    position: absolute;
    right: 0;
    top: 58px;
    background-color: rgb(73, 51, 153);
    width: 100%;
    height: calc(100vh - 58px);
    padding-top: 60px;
    gap: 10vh;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is hidden by default using the &lt;strong&gt;display: none;&lt;/strong&gt; property and should only show up when the openHam icon is clicked.&lt;br&gt;
We are going to handle this event logic using JavaScript&lt;/p&gt;
&lt;h4&gt;
  
  
  Complete CSS Code
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*, body {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: sans-serif;
}

/* Navigation */
.navigation-header {
  background-color: rgb(73, 51, 153);
  padding: 0 15px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}

nav {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo-container &amp;gt; a {
  color: ghostwhite;
  text-decoration: none;
  font-weight: 700;
  font-size: 26px;
}
.navigation-items {
  display: flex;
  gap: 40px;
}
.navigation-items &amp;gt; a {
  color: ghostwhite;
  text-decoration: none;
  font-weight: 500;
  font-size: 16px;
  transition: .4s ease-in-out;
}
.navigation-items &amp;gt; a:hover {
  color: white;
}
.hamburger {
  display: none;
  font-size: 20px;
  font-weight: 800;
  color: white;
}
@media screen and (max-width:768px) {
  .hamburger {
    display: flex;
    cursor: pointer;
  }
  .hamburger #closeHam {
    display: none;
  }
  .navigation-items {
    display: none;
    flex-direction: column;
    align-items: center;
    position: absolute;
    right: 0;
    top: 58px;
    background-color: rgb(73, 51, 153);
    width: 100%;
    height: calc(100vh - 58px);
    padding-top: 60px;
    gap: 10vh;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Step 4 Click event logic with JavaScript
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Variables for openHam, closeHam and navigationItems
&lt;/h4&gt;

&lt;p&gt;Create openHam, closeHam, and navigationItems variables and assign to elements in the HTML document using their corresponding IDs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let openHam = document.querySelector('#openHam');
let closeHam = document.querySelector('#closeHam');
let navigationItems = document.querySelector('#navigation-items');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a reusable function that controls visibility of elements.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const hamburgerEvent = (navigation, close, open) =&amp;gt; {
    navigationItems.style.display = navigation;
    closeHam.style.display = close;
    openHam.style.display = open;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code snippet defines a function called &lt;strong&gt;hamburgerEvent&lt;/strong&gt; which takes three parameters: &lt;code&gt;navigation&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;, and &lt;code&gt;open&lt;/code&gt;. Inside the function, it modifies the CSS display property of the navigationItems, closeHam, and openHam elements based on the provided values.&lt;/p&gt;

&lt;p&gt;Using an event listener, attach a click event to openHam and closeHam icons, with the hamburgerEvent function as the second parameter of the event listener:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openHam.addEventListener('click', () =&amp;gt; hamburgerEvent("flex", "block", "none"));
closeHam.addEventListener('click', () =&amp;gt; hamburgerEvent("none", "none", "block"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;openHam.addEventListener('click', () =&amp;gt; hamburgerEvent("flex", "block", "none"));&lt;/code&gt; sets up an event listener for the click event on the &lt;strong&gt;openHam&lt;/strong&gt; icon. &lt;/p&gt;

&lt;p&gt;When this element is clicked, it triggers an anonymous arrow function that calls the &lt;strong&gt;hamburgerEvent&lt;/strong&gt; function with the arguments "flex", "block", and "none". This will change the display property of &lt;strong&gt;navigationItems&lt;/strong&gt; to "flex", closeHam to "block", and openHam to "none", effectively showing the navigation items and switching the hamburger icon to the close icon. &lt;/p&gt;

&lt;p&gt;The event listener attached to the closeHam does the exact opposite of this by passing "none", "none", "block" as the parameters of the hamburgerEvent function invoked in the event listener.&lt;/p&gt;

&lt;h3&gt;
  
  
  Complete JavaScript Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let openHam = document.querySelector('#openHam');
let closeHam = document.querySelector('#closeHam');
let navigationItems = document.querySelector('#navigation-items');

const hamburgerEvent = (navigation, close, open) =&amp;gt; {
    navigationItems.style.display = navigation;
    closeHam.style.display = close;
    openHam.style.display = open;
};

openHam.addEventListener('click', () =&amp;gt; hamburgerEvent("flex", "block", "none"));
closeHam.addEventListener('click', () =&amp;gt; hamburgerEvent("none", "none", "block"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Step-by-Step Tutorial: How to Send Emails Directly from Your React Website</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Tue, 25 Apr 2023 07:54:26 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/how-to-send-emails-directly-from-your-react-website-a-step-by-step-tutorial-144b</link>
      <guid>https://dev.to/david_bilsonn/how-to-send-emails-directly-from-your-react-website-a-step-by-step-tutorial-144b</guid>
      <description>&lt;p&gt;Are you looking to make it easy for clients or customers to contact you directly from your website? Adding a message-sending feature can do just that! In this easy-to-follow tutorial, I will show you how to integrate a messaging system into your website using EmailJS. With this feature, you'll have better control and easier communication with your users and visitors. Whether you're building a portfolio website or a business landing page, this tutorial is for you! Before we dive into the technical aspect of this guide, let me quickly introduce you to EmailJS.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is EmailJS?
&lt;/h2&gt;

&lt;p&gt;EmailJS is a powerful tool that can streamline communication between your website and your users or customers with client-side code using a simple API. &lt;br&gt;
It supports various services such as Gmail, Outlook, and Yahoo to &lt;strong&gt;receive the messages sent from your website&lt;/strong&gt;. With EmailJS, you can easily integrate email sending features into your website.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to add a messaging feature to your React website using EmailJS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Sign up for an account on EmailJS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To add a messaging feature to your React website using EmailJS, the first step is to sign up for an account on their website to be able to fully use their services. &lt;a href="https://dashboard.emailjs.com/sign-up" rel="noopener noreferrer"&gt;Click here to sign up&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you are done signing up, click on the email services tab in the navigation menu, then click on 'Add new service'.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flruia2agti6d13s9flkr.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flruia2agti6d13s9flkr.jpeg" alt="Adding new services in EmailJS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
You are to select an email service you want to use to receive the messages sent from your website. This could be your personal email or company email. In this tutorial, I will be going with Gmail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7m2r03b57cyunmvfgjkg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7m2r03b57cyunmvfgjkg.jpeg" alt="email services for messaging feature on EmailJS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
After you select an email service, a new tab will be shown to you where you will see &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;Service ID&lt;/strong&gt;. You have the option to customize the name of the email service to fit your project. Copy your service ID and save it somewhere, I'd recommend Notepad for easy reach. You are also required to connect the email account you want to use for the project. Click on the connect button in blue and follow the due process that will be shown to you. &lt;/li&gt;
&lt;li&gt;
When you have successfully connected your email account, click on "Create Service".
With Gmail, you can receive up to 500 messages from the website per day.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 2: Install EmailJS service package using NPM
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
After successfully creating an account on EmailJS official website, you need to install the service package in your React project.
To install EmailJS via NPM, simply run the command below in your IDE terminal:&lt;/li&gt;
&lt;/ul&gt;

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

npm install @emailjs/browser --save


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
After the installation has been completed, you need to &lt;strong&gt;import 
emailjs library&lt;/strong&gt; using ES6 module syntax from the '@emailjs/browser'
module.
Create a EmailForm component, and import the emailjs library using the code below
```
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;import emailjs from '@emailjs/browser';&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You also need to **import emailJS CSS file** in the component using the code below...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;import './EmailForm.css';&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;####Step 4: Create form UI using JSX

- 
The next thing we need to work on is the form UI that the user will interact with and send messages from. We will build the form UI using JSX. In case you are not so familiar with building forms in React, do not worry, it is similar to how we build forms with HTML. 
Below is a snippet of a form using JSX.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;export const EmailForm = () =&amp;gt; {&lt;br&gt;
return (&lt;/p&gt;

&lt;p&gt;Send Message&lt;/p&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
- 
The code snippet above is a basic form that collects the user's email and also allows the user to write their messages directly within the `textarea`.
But it doesn't end there. We need to make the form functional.

We need to define a function in the component that will handle the form submission and send the message using the code below

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

&lt;/div&gt;



&lt;p&gt;const sendEmail = (e) =&amp;gt; {&lt;br&gt;
e.preventDefault();&lt;br&gt;
emailjs.sendForm('service_ID', 'template_ID', form.current, 'public_key')&lt;br&gt;
    .then((result) =&amp;gt; {&lt;br&gt;
        console.log(result.text);&lt;br&gt;
        console.log("message sent!")&lt;br&gt;
    }, (error) =&amp;gt; {&lt;br&gt;
        console.log(error.text);&lt;br&gt;
        console.log("error sending message, try again!")&lt;br&gt;
    });&lt;br&gt;
};&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In this code, the "sendEmail" function prevents the default form submission behavior using "e.preventDefault()". Then it uses the emailJs library to send the form data to the email address we attached earlier, which is defined by **service_ID**, **template_ID**, and **public_key** in the arguments of the "sendForm" function. The function also includes two console logs that will log the result and any errors that occur.

If you have copied your service_ID as instructed earlier, paste it where we have the service_ID in the sendForm function. You also need a template_ID which you can obtain from the dashboard on your emailJS account. 

![How to get template ID on EmailJS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n3w5ffsx15zc3ssv1xih.jpeg)

Click on the Email templates tab, go to settings, copy the entire template_ID. This is an example 'template_abcdfg'. Paste it where we have template_ID in the "sendForm" function.

To obtain the public key, on your dashboard, click on the Account tab, copy the public key and paste it where we have 'public-key' in the code.

![How to get public key or user ID on EmailJS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z66rulb41htvibcm91wt.jpeg)

You need to define a ref for the form to submit it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;const form = useRef();&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Finally, you can add an onSubmit handler to the form opening tag that will call the "sendEmail" function:

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

&lt;/div&gt;



&lt;p&gt;...&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In this code, the "ref" attribute is used to create a reference to the form, which can be passed as an argument to the "sendForm" function. The "onSubmit" attribute is used to call the "sendEmail" function when the form is submitted.

**FULL CODE SNIPPET**

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

&lt;/div&gt;



&lt;p&gt;import React, { useRef } from 'react';&lt;br&gt;
import emailjs from '@emailjs/browser';&lt;br&gt;
import './EmailForm.css';&lt;/p&gt;

&lt;p&gt;export const EmailForm = () =&amp;gt; {&lt;br&gt;
    const form = useRef();&lt;br&gt;
    const sendEmail = (e) =&amp;gt; {&lt;br&gt;
        e.preventDefault();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    emailjs.sendForm('service_ID', 'template_ID', form.current, 'public_key')
        .then((result) =&amp;gt; {
            console.log(result.text);
            console.log("message sent!")
        }, (error) =&amp;gt; {
            console.log(error.text);
            console.log("error sending message, try again!")
        });
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;return (&lt;/p&gt;

&lt;p&gt;Send Message&lt;/p&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Sending emails directly from a website is a useful feature. In this tutorial, we've explored how to do this using a library called EmailJS in a React app. By following the steps in this tutorial, you can easily send emails from your website without worrying about the complicated details. With EmailJS, sending emails is a breeze, and you can focus on building great applications without worrying about the complexities of email delivery.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to Create Responsive Containers for Your Website: Step-by-Step Tutorial</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Wed, 29 Mar 2023 13:15:07 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/how-to-create-responsive-containers-for-your-website-step-by-step-tutorial-oko</link>
      <guid>https://dev.to/david_bilsonn/how-to-create-responsive-containers-for-your-website-step-by-step-tutorial-oko</guid>
      <description>&lt;p&gt;Designing a website that looks great on all devices can be difficult, especially when it comes to creating responsive containers. &lt;/p&gt;

&lt;p&gt;These containers are layout elements that adjust their size and position based on the device's screen size, ensuring that the website looks good on any device, from a large desktop to a small mobile phone. &lt;/p&gt;

&lt;p&gt;However, writing CSS media queries to achieve this can be intimidating. Fortunately, with just a few CSS properties, you can easily make any container responsive, whether it contains text, images, or videos.&lt;/p&gt;

&lt;p&gt;This tutorial will guide you through creating responsive containers for your website, allowing your content to look great on any device. &lt;/p&gt;

&lt;p&gt;Whether you're a beginner or an experienced web developer, this tutorial will give you the necessary knowledge to design responsive web layouts that are visually appealing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single Containers
&lt;/h2&gt;

&lt;p&gt;Let's take a look at how you can make a single container responsive, whether it contains text, an image, or a video.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a container
&lt;/h3&gt;

&lt;p&gt;No matter which technology you are using - pure HTML, React, Angular, or Vue - you will need a container element such as &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This tutorial will focus on using the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; container element. Create a div element with a class of 'container'.&lt;/p&gt;

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

&amp;lt;div class="container"&amp;gt;&amp;lt;/div&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Let's have some text within the container...&lt;/p&gt;

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

&amp;lt;div class="container"&amp;gt;Write 50 - 100 words here&amp;lt;/div&amp;gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 2: Styling the container and making it responsive
&lt;/h3&gt;

&lt;p&gt;Select the container in your CSS file using its class name. Give it a background-color of your choice, and text color of your choice, and some padding if you wish to.&lt;/p&gt;
&lt;h4&gt;
  
  
  Responsiveness
&lt;/h4&gt;

&lt;p&gt;By default, a div container like this would occupy 100% width of any screen, but let's say you want to give it a defined width, you'd want that container to automatically adjust to any screen size, right? &lt;/p&gt;

&lt;p&gt;You can do that without writing media queries.&lt;br&gt;
First, give it a &lt;code&gt;width&lt;/code&gt; of 100%, then set &lt;code&gt;max-width&lt;/code&gt; to the requirement of your project. Here, we will go with 700px...&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.container {
width: 100%;
max-width: 700px;
}


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

&lt;/div&gt;

&lt;p&gt;You can center the container using &lt;code&gt;margin: auto;&lt;/code&gt; if it is required in your project.&lt;br&gt;
Using the developer tools in your browser, you can adjust the viewport of your screen to see the responsiveness of the container. Make sure to fine-tune the &lt;code&gt;max-width&lt;/code&gt; to your project's requirement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why 'max-width'?
&lt;/h3&gt;

&lt;p&gt;In responsive design, the max-width property is used to set the maximum width of an element on a webpage. This means that if the viewport or device width is less than the set max-width, the element will shrink to fit within the available space. &lt;/p&gt;

&lt;p&gt;However, if the viewport width is larger than the max-width, the element will not stretch beyond the specified width.&lt;/p&gt;

&lt;p&gt;If you only use &lt;code&gt;max-width&lt;/code&gt; without &lt;code&gt;width: 100%;&lt;/code&gt;, the container may only stretch to fit the content within it and not the full width of your requirement. &lt;/p&gt;

&lt;p&gt;Therefore, you need to include &lt;code&gt;width: 100%;&lt;/code&gt; to ensure that the container expands to fill the entire width of the screen while still adhering to the max-width limit you set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Minimum height (min-height)
&lt;/h2&gt;

&lt;p&gt;When creating containers with a fixed width, it may be necessary to specify a height for them in your project. However, if you're taking the desktop-first approach, setting a fixed height could cause the container's content to spill over on smaller devices. &lt;/p&gt;

&lt;p&gt;In other words, if you set a fixed height for a container, it may not adjust well to smaller screens, and the content inside the container could overflow or become distorted. &lt;/p&gt;

&lt;p&gt;Therefore, it's essential to keep in mind the responsiveness of your design and consider using the &lt;code&gt;min-height&lt;/code&gt; property instead.&lt;/p&gt;




&lt;p&gt;Suppose you have a container containing text with a set width and maximum width, and you want to give it a specific height of 200px. In that case, you should use the "min-height" property to set the height. &lt;/p&gt;

&lt;p&gt;This property ensures that the container's height won't be smaller than the specified value, but it can expand beyond that height to accommodate the content inside it. &lt;/p&gt;

&lt;p&gt;This way, you can keep your design consistent while allowing flexibility for different amounts of text or varying screen sizes.&lt;/p&gt;

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

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

.container {
 width: 100%;
 max-width: 600px;
 min-height: 200px;
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Flexbox display
&lt;/h3&gt;

&lt;p&gt;Flexbox is a powerful layout mode in CSS for creating dynamic and responsive user interfaces. It allows developers to easily arrange, align, and distribute elements/containers on a web page. &lt;/p&gt;

&lt;p&gt;Let's explore its fundamental concepts and how we can apply various flexbox properties to create a responsive layout.&lt;/p&gt;

&lt;p&gt;When you have multiple containers on your page that you want to align side to side, you can make use of some flexbox properties in combination with the responsive width and height properties we talked about in the earlier part of this article.&lt;/p&gt;

&lt;p&gt;As a case study, we will be working with a single-parent container and three-child containers...&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;div class="parent-container"&amp;gt;
  &amp;lt;div class="child-container"&amp;gt;A&amp;lt;/div&amp;gt;
  &amp;lt;div class="child-container"&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class="child-container"&amp;gt;C&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Give the child container a defined width and height, following the earlier principles we talked about.&lt;br&gt;
Also, apply a background-color of your choice so that we can differentiate them from the default background of the body of the page.&lt;/p&gt;

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

.child-container {
width: 100%;
max-width: 350px;
min-height: 300px;
background: dodgerblue;
}


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

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkt3xecab0f2kpzb73tlr.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkt3xecab0f2kpzb73tlr.jpeg" alt="Responsive div containers"&gt;&lt;/a&gt;&lt;br&gt;
This is what we currently have.&lt;br&gt;
To make the child containers align side to side while maintaining responsiveness, you can make use of the following flexbox properties on the &lt;strong&gt;parent-container&lt;/strong&gt;...&lt;/p&gt;

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

.parent-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    align-items: center;
}


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

&lt;/div&gt;

&lt;p&gt;This is the result below:&lt;/p&gt;

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

&lt;h4&gt;
  
  
  What does each property in the parent-container do?
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;display: flex;&lt;/code&gt;: This property defines a flex container for the element, enabling flexible layout options for its children.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;flex-wrap: wrap;&lt;/code&gt;: This property controls whether the flex items should wrap or not when they reach the end of the container. In this case, wrap means that items will wrap to a new line when they reach the end of the container.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gap: 20px;&lt;/code&gt;: This property sets the spacing between flex items. It is shorthand for the row-gap and column-gap properties, which are used to define the spacing between rows and columns respectively.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;justify-content: center;&lt;/code&gt;: This property aligns the flex items along the main axis (horizontal axis in this case) and centers them within the flex container.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;align-items: center;&lt;/code&gt;: This property aligns the flex items along the cross axis (vertical axis in this case) and centers them within the flex container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete CSS Code&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In conclusion, implementing these properties can simplify the process of creating responsive containers. Rather than writing neck-breaking media queries, you can leverage these properties to create flexible layouts that adapt to various screen sizes and devices.&lt;br&gt;
If you are a beginner, you need to have it at the back of your mind that this tutorial only serves as a guideline to responsive web design. Always tweak the max-width and min-height of your containers to the requirement of your project.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Best React UI Libraries for Simplifying Frontend Development and How to Implement Them</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Mon, 20 Mar 2023 00:40:46 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/top-react-ui-libraries-for-simplifying-frontend-development-and-how-to-implement-them-48g6</link>
      <guid>https://dev.to/david_bilsonn/top-react-ui-libraries-for-simplifying-frontend-development-and-how-to-implement-them-48g6</guid>
      <description>&lt;p&gt;Creating a visually appealing and intuitive user interface is key when it comes to developing modern websites. Developing UIs from scratch can be time-consuming and complex, you'll agree with me that React and its add-on libraries make life easier, right?&lt;br&gt;
React UI libraries are pre-built and easily customizable UI components that easily fit your application's design and functionality requirements.&lt;br&gt;
In this article, we will look at some of the top React UI libraries that can help simplify engineering on the front end and enhance your web app's user experience.&lt;br&gt;
These libraries offer a range of components that helps save time and effort while delivering a highly decorous and professional user interface. Let's take a look at the libraries one after the other and how you can implement them in your project:&lt;/p&gt;
&lt;h3&gt;
  
  
  1. React Icons
&lt;/h3&gt;

&lt;p&gt;Icons are an essential part of modern web design, providing users with visual cues and helping to make interfaces more intuitive and user-friendly. React icons provide a set of pre-built icons that can be easily customized and integrated into your project. Some of the popular icons you'll find in react icons include Ant Design icons, Bootstrap icons, Dev icons, Font Awesome 5, Material Design icons, and Game icons. It is not limited to those alone, there are several other icons that you can make use of in your project, but it is a good practice to maintain consistency for each project. Let us see how we can implement React icons in a React project.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Installation
&lt;/h4&gt;

&lt;p&gt;You need to install react-icons into your react app using the npm command below in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react-icons --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Importing the icons
&lt;/h4&gt;

&lt;p&gt;You'll need to first import the specific icon component you want to use from react-icons library. You can't possibly know the name of all icons component off the top of your head, simply go to &lt;a href="https://react-icons.github.io/react-icons/" rel="noopener noreferrer"&gt;https://react-icons.github.io/react-icons/&lt;/a&gt; and search for the specific icon you want to use. As a case study, we are going to use the warning icon component from Ant Design (ant design icons are usually the first set of results). On the website, search for 'warning', click on the icon once to copy it. Go to the specific component you want to add the icon to and import it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {AiFillWarning} from 'react-icons/ai'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: the last two letters of the texts in quotes must match the first two letters of the icon component - in this case, it is &lt;strong&gt;ai&lt;/strong&gt;...indicating &lt;strong&gt;Ant Design&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Add the icon as a component
&lt;/h4&gt;

&lt;p&gt;Let's add the icon within a single-word paragraph:&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;p&amp;gt;Caution &amp;lt;AiFillWarning/&amp;gt; &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React-icons can be easily imported and used in your project. &lt;a href="https://github.com/react-icons/react-icons" rel="noopener noreferrer"&gt;Read full documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Toast notifications using &lt;em&gt;React-toastify&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Toast notifications help with real-time feedback on users' actions, improving the overall user experience. React-toastify provides an easily customizable solution for adding toast notifications to your project. The library provides components (functional and class-based) for displaying notifications. There is a wide range of configuration options for Toastify notifications. Let's take a look at how it works and how we can implement it in a react project:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Installation
&lt;/h4&gt;

&lt;p&gt;To use Toastify in your react project, you will need to add it by running the npm command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save react-toastify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Import toastify notification
&lt;/h4&gt;

&lt;p&gt;The two components that must be imported are &lt;code&gt;**ToastContainer**&lt;/code&gt; and &lt;code&gt;**toast**&lt;/code&gt;. Use the import statement to integrate these two components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {ToastContainer, toast} from 'react-toastify'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You also need to import the pre-built styles:&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-toastify/dist/ReactToastify.css'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Create toast render function
&lt;/h4&gt;

&lt;p&gt;In your functional component, a function is needed to render the component when the user performs an action on the web page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const notify = () =&amp;gt; toast('Notification text here');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also render a component instead of a string...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const notify = () =&amp;gt; toast(&amp;lt;NewComponent/&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the onClick event on a button, let's render the notification by calling the &lt;code&gt;notify&lt;/code&gt; function...&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={notify}&amp;gt;Notify Me!&amp;lt;/button&amp;gt;
&amp;lt;ToastContainer/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the &lt;code&gt;Notify Me&lt;/code&gt; button is clicked, the &lt;code&gt;onClick&lt;/code&gt; event triggers the notify function which in turn renders the toast notification in the UI.&lt;br&gt;
&lt;strong&gt;Note: you must also render the  component for the toast notification to work.&lt;/strong&gt;&lt;br&gt;
There are configurations options that you can customize to fit into your project requirements; check out the full documentation here: &lt;a href="https://fkhadra.github.io/react-toastify/introduction/" rel="noopener noreferrer"&gt;Toastify Documentation&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3. React Modal
&lt;/h3&gt;

&lt;p&gt;React modal provides an easily customizable and accessible way to display content in a modal dialog. It is a simple and flexible solution that enables developers to create interactive UIs. React modal is highly configurable and can be easily integrated into any React application.&lt;br&gt;
Let's delve into the implementation of modals using React modal:&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Installation
&lt;/h4&gt;

&lt;p&gt;To use react modal in your react app, you will need to add it by running the npm command below in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react-modal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Import the modal from React-modal library
&lt;/h4&gt;

&lt;p&gt;After installation, you need to import the &lt;strong&gt;Modal&lt;/strong&gt; component from the library into the component you are working on using the import statement:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Add to component
&lt;/h4&gt;

&lt;p&gt;You need to render the Modal component in your project. The two configurations that must be added as props in the Modal component are &lt;code&gt;isOpen&lt;/code&gt; and &lt;code&gt;onRequestClose&lt;/code&gt;.&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;Modal
isOpen
onRequestClose
&amp;gt;
Modal contents can be written here...
&amp;lt;/Modal&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The modal need to be interactive well enough for smooth user experience. Using events and states, we can configure the modal to be interactive:&lt;br&gt;
Above the modal component, let's add a button that will trigger a click event that would make the modal pop up.&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;Open Modal&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The button doesn't do anything yet, using the useState hook, we can alter the state of the modal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [modalOpen, setModalOpen] = useState(false);
//the initial state of the modal should be set to false to keep it closed by default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The click event needs a function that will alter the state of the pop up modal by rendering it to the user interface:&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; setModalOpen(true)}&amp;gt;Open Modal&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;modalOpen&lt;/code&gt; as the value of the isOpen prop in the modal component...&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;Modal
isOpen={modalOpen}
onRequestClose
&amp;gt;
Modal contents can be written here...
&amp;lt;/Modal&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;isOpen&lt;/code&gt; prop opens and closes the modal.&lt;br&gt;
A close button has to be added to the modal component to enable the user to close the modal.&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;Modal
isOpen={modalOpen}
onRequestClose
&amp;gt;
&amp;lt;button onClick={() =&amp;gt; setModalOpen(false)}&amp;gt;Close Modal&amp;lt;/button&amp;gt;

Modal contents can be written here...
&amp;lt;/Modal&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To optimize the user experience to the max, the user needs to be able to close the modal when the overlay is clicked. The &lt;code&gt;onRequestClose&lt;/code&gt; prop allows the user to close the modal:&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;Modal
isOpen={modalOpen}
onRequestClose={() =&amp;gt; setModalOpen(false)}
&amp;gt;
&amp;lt;button onClick={() =&amp;gt; setModalOpen(false)}&amp;gt;Close Modal&amp;lt;/button&amp;gt;

Modal contents can be written here...
&amp;lt;/Modal&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to bind modal to your appElement root using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Modal.setAppElement('#root');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For styling and additional configuration, refer to full documentation here: &lt;a href="https://github.com/reactjs/react-modal" rel="noopener noreferrer"&gt;React Modal Documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Tool Tip (tippy.js)
&lt;/h3&gt;

&lt;p&gt;Tippyjs tool tip is a UI component that provides extra information about an element when users hover over an element. Tool tips are useful in creating interactive websites, providing users with relevant information without crowding the user interface.&lt;br&gt;
Let us see how we can integrate react tool tip in a project.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Installation
&lt;/h4&gt;

&lt;p&gt;To integrate tippyjs, you need to first install the npm package in the project via the terminal...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @tippyjs/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Import tippy component
&lt;/h4&gt;

&lt;p&gt;After installation, import &lt;code&gt;Tippy&lt;/code&gt; in the component you are working on, also import the ToolTip css 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 Tippy from '@tippyjs/react';
import 'tippy.js/dist/tippy.css';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Integrating to UI
&lt;/h4&gt;

&lt;p&gt;To use the Tippy component in the UI, you will wrap the component around the element you are trying to pass additional info to. See example below:&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;Tippy content="Say Hello"&amp;gt;
&amp;lt;button&amp;gt;Greet&amp;lt;/button&amp;gt;
&amp;lt;/Tippy&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tippy library provides a fast, easy and non-complex way to integrate tooltips in react.&lt;br&gt;
&lt;a href="https://github.com/atomiks/tippyjs-react" rel="noopener noreferrer"&gt;See full documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  5. AOS (Animate On Scroll) Library
&lt;/h3&gt;

&lt;p&gt;The AOS library, short for Animate on Scroll, is a powerful tool that helps to create captivating animations that trigger as users scroll through their website. In this guide, we'll explore how to use AOS to add dynamic visual effects to your website.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Installation
&lt;/h4&gt;

&lt;p&gt;Install the aos library using npm in the terminal...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install aos --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Import the library in your App component
&lt;/h4&gt;

&lt;p&gt;It is recommended to import the library to the base component, this helps to avoid importing into different child components you are working - implementing the DRY principle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import AOS from 'aos';
import 'aos/dist/aos.css';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Initialize AOS in the App component using the &lt;code&gt;useEffect&lt;/code&gt; hook. See example below:
&lt;/h4&gt;



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

function App() {
  useEffect(() =&amp;gt; {
    AOS.init();
  }, []);

  return (
    // Your component code
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4: Add data-aos to any jsx element
&lt;/h4&gt;

&lt;p&gt;There are more than 15 animation effects that can be used on elements. You have to apply the &lt;code&gt;data-aos&lt;/code&gt; attribute to be able to apply any animation effect.&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;div data-aos="fade-up"&amp;gt;Animate me!&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meanwhile, keep in mind that you have already initialized the library in the base component which is the App component, so you do not need to initialize it anywhere else.&lt;br&gt;
&lt;a href="https://github.com/michalsnik/aos" rel="noopener noreferrer"&gt;See full AOS documentation&lt;/a&gt;. &lt;a href="https://michalsnik.github.io/aos/" rel="noopener noreferrer"&gt;See all animation effects&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are many other useful libraries that aren't discussed in this article, we will take a look at them in the sequel (part 2) of this article. I hope you found this article useful, let me know your thoughts in the comment section.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to return multiple items in a map function in JavaScript</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Sat, 04 Mar 2023 11:18:40 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/how-to-return-multiple-items-in-a-map-function-in-javascript-eip</link>
      <guid>https://dev.to/david_bilsonn/how-to-return-multiple-items-in-a-map-function-in-javascript-eip</guid>
      <description>&lt;p&gt;The &lt;code&gt;map()&lt;/code&gt; function enables you to loop over every element in an array, modify it and then return a different element to replace the initial element. The &lt;code&gt;map()&lt;/code&gt; function does not change the original array, you will still have the same amount of elements as the original array.&lt;/p&gt;




&lt;p&gt;The &lt;code&gt;map()&lt;/code&gt; method takes a function that accepts three arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first argument is the current value&lt;/li&gt;
&lt;li&gt;Second argument is the index&lt;/li&gt;
&lt;li&gt;The third argument is the original array&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's take a deeper look into this with an example;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Create an array...&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;let val = [1, 2, 3, 4];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Using the &lt;code&gt;map()&lt;/code&gt; function, iterate through every element in the array...&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;let newVal = val.map((v) =&amp;gt; {
 return [v*v, v*v*v, v+1];
});

//log 'newVal' into console

console.log(newVal);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The map function will return a new array in the console. &lt;/p&gt;

&lt;p&gt;Let us go through an array of programming languages;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let languages = ["Kotlin", "Java", "Rust", "React", "Node", "Python"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to create a map function, inside this function, we need to have a return statement and whatever we return will become the content of the new array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let languages = ["Kotlin", "Java", "Rust", "React", "Node", "Python"];

//log the variable to console to see the languages array

console.log(languages);

//now let's make use of the map function

let langLength  = languages.map(function(item, index, array) {
return 6;
});

//log langLength to console

console.log(langLength);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will observe that the new array now has six 6s in it.&lt;/p&gt;

&lt;p&gt;Let us put an index in the array and see what it returns...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let langLength = languages.map(function(item, index, array){
return index;
});

//log langLength to console

console.log(langLength);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see in your console that it outputs the index number of each item in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Now, pass in the third argument of the function to the return statement...&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;let langLength = languages.map(function(item, index, array){
return array;
})

//log langLength to console to see the output

console.log(langLength);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see in the console that each item in the array has now been listed.&lt;/p&gt;

&lt;h3&gt;
  
  
  A better approach to returning multiple items from an array is by using the &lt;code&gt;flatMap()&lt;/code&gt; function...
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const num = [2, 4, 6, 8];
const newNum = num.flatMap((v) =&amp;gt; [v*v, v*v*v, v+1]);
console.log(JSON.stringify(newNum));

//You should have a result like this: [4,8,3,16,64,5,36,216,7,64,512,9]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;map()&lt;/code&gt; function in JavaScript returns a new array with the same number of elements as the original array. If you want to create a new array with a different number of elements, you may need to use a different function such as &lt;code&gt;filter()&lt;/code&gt;, &lt;code&gt;reduce()&lt;/code&gt;, or &lt;code&gt;flatMap()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;flatMap()&lt;/code&gt; function is available as a built-in function on arrays in JavaScript. It works similarly to the &lt;code&gt;map()&lt;/code&gt; function, but it also flattens the output into a single array. This means that if the function applied by &lt;code&gt;flatMap()&lt;/code&gt; returns an array, the elements of that array are included in the final output array.&lt;/p&gt;

&lt;p&gt;I hope you have found this article helpful. Please take a moment to share your feedback in the CS. Thank you for reading.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>career</category>
      <category>salary</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How to save a string to clipboard in JavaScript</title>
      <dc:creator>David Bilson</dc:creator>
      <pubDate>Wed, 01 Mar 2023 17:00:39 +0000</pubDate>
      <link>https://dev.to/david_bilsonn/how-to-save-a-string-to-clipboard-in-javascript-13ie</link>
      <guid>https://dev.to/david_bilsonn/how-to-save-a-string-to-clipboard-in-javascript-13ie</guid>
      <description>&lt;p&gt;There are a few methods that can be used to copy a string to clipboard in JavaScript. It is important to know how to save/copy a string to clipboard when building websites and web-based applications.&lt;/p&gt;

&lt;p&gt;To simply save a string to clipboard, you have to ensure navigator - navigator.clipboard and navigator.clipboard.writeText are used correctly. &lt;/p&gt;

&lt;p&gt;Clipboard.writeText() allows you to copy the string value directly to clipboard. We will see how this works shortly.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Let’s take for example;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You create a string and store it as a variable…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let stringText = “This is the text to be copied to clipboard”;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After creating the string and storing it as a variable, you have to create a function that lets you copy the string to clipboard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let stringText = 'I am a text copied to clipboard';

function copyBtn() {

navigator.clipboard.writeText(stringText);

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

&lt;/div&gt;



&lt;p&gt;If the function &lt;strong&gt;copyBtn()&lt;/strong&gt; is assigned to an onClick event in an html element, when clicked on, the value of the string will immediately be copied to clipboard.&lt;/p&gt;

&lt;p&gt;Let’s create an example with a &lt;strong&gt;html button&lt;/strong&gt; which would have a click event that would enable you copy the string to clipboard which you can then paste anywhere.&lt;/p&gt;

&lt;p&gt;Remember to pass the &lt;strong&gt;copyBtn()&lt;/strong&gt; function to the click event.&lt;/p&gt;

&lt;p&gt;First create a text area in your HTML that you can paste the string to.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;textarea name='textarea' placeholder='paste your link here' cols='30' rows='5'&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a button below the textarea&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;button onclick='copyBtn()'&amp;gt;Click here to copy text to clipboard&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open the html file in your browser, then click on the button. The string stored in the &lt;strong&gt;stringText&lt;/strong&gt; variable will be copied to clipboard, you can then paste it within the textarea. &lt;/p&gt;

&lt;p&gt;Okay, now you are thinking "Can't I make everything happen within HTML?"... Of course you can. How? You can create a paragraph and store its textContent as variable. The &lt;strong&gt;copyBtn&lt;/strong&gt; function can then fetch the variable and store the textContent of the paragraph in the clipBoard. Go ahead and give it a try.&lt;/p&gt;

&lt;p&gt;Make sure your JavaScript file is linked to your HTML file unless you are writing JS in HTML then the JavaScript codes should go within the  tag.&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;I hope you found this article useful. You can check other articles I have written on JavaScript and some of the best practices. &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;If there are other ways that a string can be copied to clipboard, kindly state them in the comment section.&amp;lt;/p&amp;gt;
&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
