Quickupdate

  • Home
  • Top Trending
    • Top Android Apps
    • Top Ios Apps
  • Featured
  • About Us
  • Contact us
  • Privacy Policy and Disclaimer

Saturday, 19 June 2021

Create Login Form with React in Hindi | Handling Basic Form with React Hook

 Developers     June 19, 2021     React     No comments   

Basic form in React js. User can enter mail id and password and Onclick on submit button I am getting values from the input fields and showing back to the user.

Also you can use the React Developer Tools extension to see the data in hooks.

import React, {useState} from 'react';

const Basicform = () => {

    // creating state value's
    const [email, setEmail] = useState("");
    const [password, setPassword] = useState("");

    const [allEntry, setAllEntry] = useState([]);
     const submitForm = (e) => {
         e.preventDefault();
         const newEntry = {email:email, password:password};
         setAllEntry([...allEntry, newEntry]);
     }
    return (
        <>
            <form action="post" onSubmit={submitForm}>
                <div>
                    <label htmlFor="email">Email</label>
                    <input type="email" name="email" id="email" 
                        value={email} 
                        onChange={(e) => setEmail(e.target.value)} 
                        autocomplete="off"/>
                </div>

                <div>
                    <label htmlFor="password">Password</label>
                    <input type="password" name="password" 
                        id="password" value={password} 
                        onChange={(e) => 
                        setPassword(e.target.value)}/>
                </div>
                <div>
                    <button type="submit" name="loginBtn">Login</button>
                </div>
            </form>
            
            <div>
                {allEntry.map( (currentElemet) => {
                    return (
                        <>
                            <div>
                                <p>{currentElemet.email}</p>
                                <p>{currentElemet.password}</p>
                            </div>
                        </>
                    )
                })}
            </div>
        </>
    )
}
export default Basicform
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Popular Posts

  • How to upload the existing folder on GitHub Or GitLab?
    These are the steps to upload the existing folder on GitHub Or GitLab. Whenever you want to push your existing folder to git or GitHub you m...

Categories

  • FAANG (2)
  • Javascript (6)
  • Node (1)
  • Project Management (1)
  • React (9)
  • SQL (1)
  • Testing (1)

Blog Archive

  • January 2023 (1)
  • January 2022 (1)
  • November 2021 (3)
  • October 2021 (3)
  • August 2021 (1)
  • July 2021 (7)
  • June 2021 (12)
  • February 2021 (1)
  • January 2021 (1)
  • January 2020 (3)
  • August 2019 (3)