codelover
codelover

Reputation: 131

storing data in useState hooks

i have an input tag for taking old and new password. I want to store it in a useState hook. How do I do that? here is the code of the input tag:

<Form.Control
                  type="password"
                  placeholder="Confirm new password"
                  name="checkPassword"
                  value={values.checkPassword}
                  onChange={handleChange}
                />

here is the useState hook:

 const [password, setPassword] = useState("");

Upvotes: 1

Views: 680

Answers (1)

Mahdi Aryayi
Mahdi Aryayi

Reputation: 1120

1- change the value into value={password}

2- change the onChange into onChange={(e) => setPassword(e.target.value)}

P.S. if your element is a standard HTML input with e.target.value. if not, you have to pass the correct argument to the onChange event.

Upvotes: 2

Related Questions