showing results for - "react function with form"
Isra
04 May 2017
1import React, {useState} from 'react';
2
3function Submit() {
4
5    const [inputField , setInputField] = useState({
6        first_name: '',
7        last_name: '',
8        gmail: ''
9    })
10
11    const inputsHandler = (e) =>{
12        setInputField( {[e.target.name]: e.target.value} )
13    }
14
15    const submitButton = () =>{
16        alert(inputField.first_name)
17    }
18
19    return (
20        <div>
21            <input 
22            type="text" 
23            name="first_name" 
24            onChange={inputsHandler} 
25            placeholder="First Name" 
26            value={inputField.first_name}/>
27
28            <br/>
29
30            <input 
31            type="text" 
32            name="last_name" 
33            onChange={inputsHandler} 
34            placeholder="First Name" 
35            value={inputField.last_name}/>
36
37            <br/>
38
39            <input 
40            type="gmail" 
41            name="gmail" 
42            onChange={inputsHandler} 
43            placeholder="Gmail" 
44            value={inputField.gmail}/>
45
46            <br/>
47
48            <button onClick={submitButton}>Submit Now</button>
49        </div>
50    )
51}
52
53export default Submit
54