<?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: Chinedu Onuwa</title>
    <description>The latest articles on DEV Community by Chinedu Onuwa (@iamonuwacj).</description>
    <link>https://dev.to/iamonuwacj</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%2F1261455%2F4eedb597-d1c5-4e5e-ae00-914e054f663d.jpeg</url>
      <title>DEV Community: Chinedu Onuwa</title>
      <link>https://dev.to/iamonuwacj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamonuwacj"/>
    <language>en</language>
    <item>
      <title>🐛 Don’t Let This Mongoose Bug Waste Your Time in Next.js</title>
      <dc:creator>Chinedu Onuwa</dc:creator>
      <pubDate>Fri, 13 Jun 2025 20:27:55 +0000</pubDate>
      <link>https://dev.to/iamonuwacj/dont-let-this-mongoose-bug-waste-your-time-in-nextjs-4308</link>
      <guid>https://dev.to/iamonuwacj/dont-let-this-mongoose-bug-waste-your-time-in-nextjs-4308</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I spent hours wondering why my MongoDB documents only had an &lt;code&gt;_id&lt;/code&gt; field after saving — and the fix turned out to be ridiculously simple.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you're using &lt;strong&gt;Mongoose with the Next.js App Router&lt;/strong&gt; and noticing that only the &lt;code&gt;_id&lt;/code&gt; is being saved to MongoDB (while fields like &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, &lt;code&gt;createdAt&lt;/code&gt;, and &lt;code&gt;updatedAt&lt;/code&gt; are mysteriously missing), this article is for you.&lt;/p&gt;

&lt;p&gt;I'll walk you through the exact bug, what caused it, and how to fix it in 3 seconds — before it wastes as much of your time as it did mine.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔧 The Stack
&lt;/h2&gt;

&lt;p&gt;I was building a simple signup API &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Nextjs 13]&lt;/li&gt;
&lt;li&gt;MongoDB (via Mongoose)&lt;/li&gt;
&lt;li&gt;Thunder Client (for testing)&lt;/li&gt;
&lt;li&gt;App Router (&lt;code&gt;/app/auth/signup&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything was fine... until it wasn’t and i started sweating, cussing and had to nose dive into nextjs documentation.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚨 The Weird Bug
&lt;/h2&gt;

&lt;p&gt;I sent a &lt;code&gt;POST&lt;/code&gt; request to my &lt;code&gt;/api/auth/signup&lt;/code&gt; route with this JSON body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"iamonuwacj"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"iamonuwacj@example.com"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Response I keep getting&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "_id": "665eaa...",
  "__v": 0
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No name, no email, no createdAt, no updatedAt. Just _id.&lt;/p&gt;

&lt;p&gt;But here’s the kicker:&lt;br&gt;
✅ console.log(await req.json()) showed the correct data.&lt;br&gt;
✅ The MongoDB connection was successful.&lt;br&gt;
✅ No error messages were thrown.&lt;/p&gt;

&lt;p&gt;So... why was only the _id saved?&lt;br&gt;
What happened to the data I posted??&lt;/p&gt;

&lt;p&gt;🧠 *&lt;em&gt;The Real Cause *&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The issue? Mongoose model caching during hot reload.&lt;/li&gt;
&lt;li&gt;In dev mode, when the Next.js server hot-reloads, it may:&lt;/li&gt;
&lt;li&gt;Recompile the same schema multiple times&lt;/li&gt;
&lt;li&gt;Corrupt the internal Mongoose model&lt;/li&gt;
&lt;li&gt;Silently break how fields are mapped and saved&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, my model looks fine — but Mongoose stopped applying the schema properly.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;The Fix&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔁 1. Restart the dev server and clear cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Stop the server
Ctrl + C

# Clear the Next.js build cache
rm -rf .next

# Restart dev
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom 💥. Fields started saving again, along with timestamps.&lt;/p&gt;

&lt;p&gt;✅ 2. Use Defensive Mongoose Model Export &lt;/p&gt;

&lt;p&gt;Make sure your model is exported like this to avoid duplicate declarations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default mongoose.models.User || mongoose.model('User', UserSchema); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents Mongoose from re-declaring models when the app reloads.&lt;/p&gt;

&lt;p&gt;🛠 Sample example for the models /models/User.js&lt;br&gt;
&lt;/p&gt;

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

const UserSchema = new mongoose.Schema({
  name: { type: String, required: true },
  email: { type: String, required: true }
}, { timestamps: true });

export default mongoose.models.User || mongoose.model('User', UserSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;/api/auth/signup/route.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import connectDB from '@/lib/db';
import User from '@/models/User';

export async function POST(req) {
  try {
    await connectDB();

    const body = await req.json();
    const { name, email } = body;

    const user = new User({ name, email });
    await user.save();

    return new Response(JSON.stringify(blog), {
      status: 201,
      headers: { 'Content-Type': 'application/json' }
    });

  } catch (err) {
    console.error("Error:", err);
    return new Response(JSON.stringify({ error: 'Server error' }), {
      status: 500
    });
  }
}

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

&lt;/div&gt;



&lt;p&gt;🔎 Thunder Client Request (for testing)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;POST &lt;a href="http://localhost:3000/api/auth/signup" rel="noopener noreferrer"&gt;http://localhost:3000/api/auth/signup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Headers: Content-Type: application/json&lt;/li&gt;
&lt;li&gt;Body:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "iamonuwacj",
  "email": "iamonuwacj@example.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Now, It Works! &lt;/p&gt;

&lt;p&gt;MongoDB now saved the document like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ "_id": "665eaa...", "name": "iamonuwacj", "email": "iamonuwacj@example.com", "createdAt": "2025-06-13T18:55:23.123Z", "updatedAt": "2025-06-13T18:55:23.123Z", "__v": 0 } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧠 &lt;strong&gt;Takeaways&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When using Mongoose + Next.js App Router, always:&lt;/li&gt;
&lt;li&gt;Export models defensively&lt;/li&gt;
&lt;li&gt;Clear .next cache if things act weird&lt;/li&gt;
&lt;li&gt;If only _id is saved:&lt;/li&gt;
&lt;li&gt;Your schema isn't applied correctly&lt;/li&gt;
&lt;li&gt;You're likely using a stale or broken model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have You Faced This? &lt;/p&gt;

&lt;p&gt;Let me know if this saved your day (or night)!&lt;br&gt;
I would love to hear your Mongoose war stories&lt;/p&gt;

&lt;p&gt;Happy debugging&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>mongoose</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Form Validation made easy for beginners. Learn how to monitor states in react</title>
      <dc:creator>Chinedu Onuwa</dc:creator>
      <pubDate>Wed, 23 Apr 2025 02:46:25 +0000</pubDate>
      <link>https://dev.to/iamonuwacj/form-validation-made-easy-for-beginners-learn-how-to-monitor-states-in-react-ld1</link>
      <guid>https://dev.to/iamonuwacj/form-validation-made-easy-for-beginners-learn-how-to-monitor-states-in-react-ld1</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li" class="crayons-story__hidden-navigation-link"&gt;Beginner's Guide to Form Validation&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/iamonuwacj" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1261455%2F4eedb597-d1c5-4e5e-ae00-914e054f663d.jpeg" alt="iamonuwacj profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/iamonuwacj" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Chinedu Onuwa
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Chinedu Onuwa
                
              
              &lt;div id="story-author-preview-content-2425554" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/iamonuwacj" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1261455%2F4eedb597-d1c5-4e5e-ae00-914e054f663d.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Chinedu Onuwa&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 23 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li" id="article-link-2425554"&gt;
          Beginner's Guide to Form Validation
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/tutorial"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;tutorial&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              2&lt;span class="hidden s:inline"&gt; comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Beginner's Guide to Form Validation</title>
      <dc:creator>Chinedu Onuwa</dc:creator>
      <pubDate>Wed, 23 Apr 2025 02:43:54 +0000</pubDate>
      <link>https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li</link>
      <guid>https://dev.to/iamonuwacj/beginners-guide-to-form-validation-35li</guid>
      <description>&lt;p&gt;When building web applications, we use forms to collect inputs from users. Every form field serves a purpose on the application. Forms makes collection of user input like: login details, sign-up information or user feedback easy to collect and analyse.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is Form Validation?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Form validation is the process of checking if the data entered by a user is correct and complete before sending it to the server&lt;br&gt;
Form validation helps to prevent users from submitting a form with invalid  or missing information. For example we can check &lt;em&gt;if&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the email typed is correct&lt;/li&gt;
&lt;li&gt;password is long enough&lt;/li&gt;
&lt;li&gt;No required field is empty&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, I will work you through on how to do basic form validation with reactjs&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;We will build a simple signup form with three fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Email&lt;/li&gt;
&lt;li&gt;Password&lt;/li&gt;
&lt;li&gt;Username&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step by Step Example
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;*&lt;em&gt;Basic Setup *&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Firstly, we will create a react app with:&lt;br&gt;
&lt;code&gt;npm create vite@latest&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
follow the prompt as shown below&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favj7t9rh9eqzlbizbt7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favj7t9rh9eqzlbizbt7q.png" alt="install vite" width="800" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6gxgbd8vi4wkbv1w0zd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6gxgbd8vi4wkbv1w0zd.png" alt="select a variant" width="800" height="654"&gt;&lt;/a&gt;&lt;br&gt;
Now run the commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  cd &amp;lt;formValidation&amp;gt;
  npm install
  npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace formValidation with your project name&lt;/p&gt;

&lt;p&gt;Now lets create our signUp Form&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//SignUpForm.jsx

import React, { useState } from 'react'

const SignUpForm = () =&amp;gt; {
    // use useState to monitor all the input values and error state
    const [userName, setUserName] = useState("")
    const [email, setEmail] = useState("")
    const [password, setPassword] = useState("")
    const [error, setError] = useState({})


    // submit the form
    const handleSubmit = (e) =&amp;gt; {
        e.preventDefault()

        let formErrors = {}

        // validateing the username field
        if(!userName){
            formErrors.userName = "User Name cannot be empty"
        }


        // validateing the email field
        if(!email){
            formErrors.email = "Email is required"
        }else if(!/\S+@\S+\.\S+/.test(email)){
            formErrors.email = "Email is Invalid"
        }

        // validating the password field
        if(!password){
            formErrors.password = "Password is required"
        }else if(password.length &amp;lt; 8){
            formErrors.password = "Password must be at least 8 characters"
        }

        //add the errors
        setError(formErrors)

        // submit if there is no error and reset the input values
        if(Object.keys(formErrors).length === 0) {
            alert("Form submitted successfully")
            setEmail("")
            setPassword("")
            setUserName("")
        }
    }


  return (
    &amp;lt;form className='form-container' onSubmit={handleSubmit}&amp;gt;
        &amp;lt;h2&amp;gt;Sign Up&amp;lt;/h2&amp;gt;

        &amp;lt;div className='form-group'&amp;gt;
            &amp;lt;label htmlFor=""&amp;gt;Username&amp;lt;/label&amp;gt;
            &amp;lt;input type="text"
                value={userName}
                onChange={(e) =&amp;gt; setUserName(e.target.value)}
            /&amp;gt;

            {error.userName &amp;amp;&amp;amp;  &amp;lt;p className='error'&amp;gt;{error.userName}&amp;lt;/p&amp;gt;}
        &amp;lt;/div&amp;gt;
        &amp;lt;div className='form-group'&amp;gt;
            &amp;lt;label htmlFor=""&amp;gt;Email&amp;lt;/label&amp;gt;
            &amp;lt;input type="email"
                value={email}
                onChange={(e) =&amp;gt; setEmail(e.target.value)}
            /&amp;gt;
            {error.email &amp;amp;&amp;amp;  &amp;lt;p className='error'&amp;gt;{error.email}&amp;lt;/p&amp;gt;}
        &amp;lt;/div&amp;gt;
        &amp;lt;div className='form-group'&amp;gt;
            &amp;lt;label htmlFor=""&amp;gt;Password&amp;lt;/label&amp;gt;
            &amp;lt;input type="password"
                value={password}
                onChange={(e) =&amp;gt; {setPassword(e.target.value)}}
            /&amp;gt;
            {error.password &amp;amp;&amp;amp;  &amp;lt;p className='error'&amp;gt;{error.password}&amp;lt;/p&amp;gt;}
        &amp;lt;/div&amp;gt;

        &amp;lt;button&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  )
}

export default SignUpForm
&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;//App.jsx

import './App.css'
import SignUpForm from './signUpForm'

function App() {


  return (
    &amp;lt;div className='container'&amp;gt;
      &amp;lt;SignUpForm /&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;p&gt;For the CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//App.css

* {
    padding: 0;
    margin: 0;
}

.container {
    height: 100vh;
    background-color: gray;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-container {
    min-width: 400px;
    background-color: rgb(158, 128, 186);
    padding: 20px;
    border-radius: 10px;
}

h2 {
    font-size: 30px;
    margin-bottom: 30px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 30px;
    position: relative;
}

.error {
    position: absolute;
    bottom: -18px;
    left: 5px;
    color: red;
}


input {
    padding: 10px 20px;
    background-color: gray;
    border: none;
}

label {
    font-size: 20px;
}

button {
    width: 100%;
    padding: 10px;
    background: #000;
    color: white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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