Reputation: 1
I'm a beginner in React. I want to show a form by clicking on an <a></a>
tag, please help me. I searched a lot but didn't figure out how to do it.
<a href="#adduser" onClick={viewData}>
Add new user
</a>
by clicking on "Add new user" a form will be opened. Can anyone help me with that?
Upvotes: 0
Views: 654
Reputation: 408
import React, { useState } from 'react';
export function FormBlock() {
const [showForm, setFormStatus] = useState(false);
const viewData = () => setFormStatus(true);
return (
<div>
<a href="#adduser" onClick={viewData}>Add new user</a>
{showForm && (
<form>
<input />
<button type="submit">submit</button>
</form>
)}
</div>
);
}
Upvotes: 2