Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react declare multiple states

import React,{useState} from 'react'

//Declare multiple states as a single object
let [userData,setUserData]=useState({
        email:'',
        password:'',
    })

//handler function
const handleChange = (event) => {
        event.preventDefault()
        const value=event.target.value
        setUserData({...userData,[event.target.name]:value});
      }
      
 
PREVIOUS NEXT
Tagged: #react #declare #multiple #states
ADD COMMENT
Topic
Name
5+6 =