0

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?

1

1 Answer 1

2
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>
  );
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.