Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Render a component by clicking a link in React

I'm building a story in storybook, but that isn't too relevant to the question at hand. Basically, I need to build a situation where I have an anchor tag that, when clicked, opens a dialog box/modal window. The dialog is a component, <Dialog />. I'm mocking it up as something that looks like:

<a onclick={launches Dialog component}>Click Me</a>

This seems like a simple question and I just don't know the answer. I appreciate the help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You'd have a few ways to achieve your needs.

  1. Using useState and conditional rendering
const [open, setOpen] = useState(false)
<a onClick={() => setOpen(true)}>Click Me</a>
{open && <MyComponent />}
  1. Using useState and css
const [open, setOpen] = useState(false)
<a onClick={() => setOpen(true)}>Click Me</a>
{/* You could use visibility instead of display */}
<MyComponent style={{display: open ? 'block' : 'none'}} />
  1. In case of a new window, I'd recommend using some external library such as react-new-window
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!