Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: reuse the container div if its already avaiable in DOM #3

Open
saswat3115 opened this issue Jul 12, 2021 · 3 comments
Open

Comments

@saswat3115
Copy link

saswat3115 commented Jul 12, 2021

let container = document.getElementById('custom-modal');
if (!container) {
    container = document.createElement('div');
    container.id = 'custom-modal';
    document.body.appendChild(container);
}
@saswat3115
Copy link
Author

Sometimes when we use hot reloding (ex:- create-react-app) that time multiple instance of popup is creating in DOM. To avoid that you can add this peace of code

@e1himself
Copy link
Contributor

e1himself commented Sep 16, 2021

Hi @saswat3115!

Thanks for submitting this suggestion.

I've been thinking about the best way to approach this. Just always overwriting the previous div doesn't sound like a great idea to me, as it will probably be very unexpected for most of the users. However, your use-case does make sense as well.

I've come to an idea, where we can pass optional key or id or element property into the reactModal() function to instruct it to reuse the existing div matching the given selector, if any.

What do you think about such solution?

@saswat3115
Copy link
Author

let container = document.getElementById('custom-modal');
if (!container) {
    container = document.createElement('div');
    container.id = 'custom-modal';
    document.body.appendChild(container);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants