Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get input value in react using hooks

import React, {useState} from 'react'

export default () => {
    const [fName, setfName] = useState('');
    const [lName, setlName] = useState('');
    const [phone, setPhone] = useState('');
    const [email, setEmail] = useState('');

const submitValue = () => {
    const frmdetails = {
        'First Name' : fName,
        'Last Name' : lName,
        'Phone' : phone,
        'Email' : email
    }
    console.log(frmdetails);
}

return(
    <>
    <hr/>
    <input type="text" placeholder="First Name" onChange={e => setfName(e.target.value)} />
    <input type="text" placeholder="Last Name" onChange={e => setlName(e.target.value)} />
    <input type="text" placeholder="Phone" onChange={e => setPhone(e.target.value)} />
    <input type="text" placeholder="Email" onChange={e => setEmail(e.target.value)} />
    <button onClick={submitValue}>Submit</button>
    </>
    )
}
Comment

Handle an input with React hooks

  const [inputValue, setInputValue] = React.useState("");

      const onChangeHandler = event => {
        setInputValue(event.target.value);
      };

      <input
        type="text"
        name="name"
        onChange={onChangeHandler}
        value={inputValue}
      />
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript es6 check if index exists 
Javascript :: js listen for class change event 
Javascript :: jquery summernote set value 
Javascript :: how to get the max value of two variables in math 
Javascript :: angular datatable reload with pagination 
Javascript :: move div with the mouse in js 
Javascript :: print table javascript 
Javascript :: javscript foreach with click listener 
Javascript :: javascript sum array 
Javascript :: add item to list javascript 
Javascript :: on hover add class on children jquery 
Javascript :: jquery get element max height 
Javascript :: dynamic copyright year js 
Javascript :: vue get element height 
Javascript :: node js throw error 
Javascript :: react on focus out 
Javascript :: eject expo app to android and react native 
Javascript :: internal/modules/cjs/loader.js:1122 return process.dlopen(module, path.toNamespacedPath(filename)); 
Javascript :: localstorage remove item 
Javascript :: how to install react router dom 
Javascript :: usestate remove from array 
Javascript :: how to align text vertically center beside an image in react native 
Javascript :: jquery animation 
Javascript :: remove double slash from url javascript 
Javascript :: jquery array remove element 
Javascript :: File type node js 
Javascript :: Use History React Router v5 app 
Javascript :: chartjs hide text inside bar 
Javascript :: Two different lockfiles found: package-lock.json and yarn.lock 
Javascript :: js paste 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =