Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
What's the correct way to implement a modal in a production grade webapp?
Post Flair (click to view more posts with a particular flair)
Post Body

I'm working on a React webapp and I'm trying to implement a set of modals, all with the same styling, but with different bodies, but the way different libraries and tutorials tell you to do it doesn't make that much sense to me. What they suggest is that I should embed the modal body below the button that's going to toggle it, but that doesn't make a lot of sense in my head.

Coming from different frameworks, what I'd do is create a generic modal that, using functions to open and close it, it'd get rendered inside an empty modal container HTML element, and I'd extend from that generic modal to make every modal I need.

For react, using exclusively functional components, I was thinking about creating a modal factory, a (non JSX) function that receives the body of the modal, places it inside the generic, renders it invisible inside the container, and returns an object with the two methods to interact with a state hook that would toggle it's visibility. I've tried doing this but I'm getting errors related to the hooks, which leads me to believe you're not meant to do it like that hahahah

My question is, how should I tackle this problem? How do I create that sort of generic modal/modal factory for my project?

Author
Account Strength
100%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
15,158
Link Karma
6,481
Comment Karma
8,225
Profile updated: 2 days ago
Posts updated: 9 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago