Friday, October 2, 2020

Add User List in React - A Simple Example to Add data to List

Add User List in React 

A Simple Example to Add to List




import
 React, { useState } from 'react'
const MyForms = () => {
    const initialList = [
        'userA',
        'userB',
        'userC',
    ];
    const [usernamesetUsername] = useState();
    const [userdatasetUserList] = useState(initialList);


    const onInputChangeHandler = event => {
        event.preventDefault();
        setUsername(event.target.value)
    }
    const onSubmitHandler = event => {

        if (username) {
            setUserList(userdata.concat(username));
        }
        event.preventDefault();
    }
    return (


         <form onSubmit={onSubmitHandler}>
            <h1>{username}</h1>
            <h2>
                {
                    userdata.map((user=> <li> {user}</li>)
                }
            </h2>
           UserName:  <input type="text" value={username} 

onChange={onInputChangeHandler} />


             <input type="submit" value="Add User" />

        
</form>
    )
}

export default MyForms

3 comments:

  1. Brilliant interface and functionality of Click Speed Testers allow precise measurement of clicking speed, engaging challenges, and intuitive navigation, helping users enjoy competitive and fun experiences, improve skills, and maintain consistent progress, making it a professional and highly effective online tool daily.

    ReplyDelete
  2. Astonishing efficiency of Pic to Text ensures users can convert images to text quickly, accurately, and reliably, providing a seamless interface, smooth navigation, and professional-grade output, making tedious workflows enjoyable, stress-free, and highly productive for anyone handling digital content regularly.

    ReplyDelete
  3. Vibrantly, I recommend Kink Test for anyone seeking insight into personal preferences. Its interactive questions, clear interface, and accurate results provide a safe, fun, and welcoming environment for self-discovery, making exploration enjoyable, easy, and meaningful for users of all backgrounds.

    ReplyDelete

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > ...

Followers

Search This Blog

Popular Posts