• Register

Approach

  • I am going to explain how to use state in React.js
  • At first, you should import the function to use state from the React module.
  • and then declare the variables like the below example.

Program

import React, { useState } from "react"
const InputForm = () => {
    const [email, setEmail] = useState("");
    const [password, setPassword] = useState("");
    return(
        <>
            <input placeholder="Email" type="email" onChange={(e) => setEmail(e.target.value)} />
            <input placeholder="Password" type="password" onChange={(e) => setPassword(e.target.value)} />
        </>
    )
}
100 points
3