Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Functional Component State Management

import React, {useState} from 'react';

function Submit() {

    const [inputField , setInputField] = useState({
        first_name: '',
        last_name: '',
        gmail: ''
    })

    const inputsHandler = (e) =>{
        setInputField( {[e.target.name]: e.target.value} )
    }

    const submitButton = () =>{
        alert(inputField.first_name)
    }

    return (
        <div>
            <input 
            type="text" 
            name="first_name" 
            onChange={inputsHandler} 
            placeholder="First Name" 
            value={inputField.first_name}/>

            <br/>

            <input 
            type="text" 
            name="last_name" 
            onChange={inputsHandler} 
            placeholder="First Name" 
            value={inputField.last_name}/>

            <br/>

            <input 
            type="gmail" 
            name="gmail" 
            onChange={inputsHandler} 
            placeholder="Gmail" 
            value={inputField.gmail}/>

            <br/>

            <button onClick={submitButton}>Submit Now</button>
        </div>
    )
}

export default Submit
Comment

PREVIOUS NEXT
Code Example
Javascript :: react fragment inside map with key prop 
Javascript :: fs flies in dir 
Javascript :: buffer to image nodejs 
Javascript :: why does an array index start at 0 
Javascript :: react form 
Javascript :: how draw table from json ajax 
Javascript :: react image source showing object module 
Javascript :: black adam 
Javascript :: serve static files from express 
Javascript :: conditional (ternary) operator function parameter 
Javascript :: remove from array javascript 
Javascript :: array of array key value javascript 
Javascript :: moment time from now 
Javascript :: alert function in javascript 
Javascript :: bootstrap 5 with next js 
Javascript :: array spread operator in javascript 
Javascript :: sum range javascript 
Javascript :: propertyName nuxt auth 
Javascript :: javascript prevent iframe interaction 
Javascript :: online javascript compiler 
Javascript :: range in javascript 
Javascript :: JavaScript next() Method 
Javascript :: format string javascript 
Javascript :: how to select a few properties from an object javascript 
Javascript :: get bytes from string javascript 
Javascript :: nested dto nestjs 
Javascript :: how to add multiple styles in javascript 
Javascript :: delete element from array js 
Javascript :: dynamic set required in angular using formcontrol 
Javascript :: array some 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =