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

115
Views
Create svelte component on every click

I'm trying to create new instances of the same component in svelte whenever a button or other action happens on the page, without having to make a list and {each} over them. I just want to do something like new Component(some context data) and forget. Another concern is I don't want the component to disappear when the parent is removed.

Thank you

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

0

Just mount it straight on the document.body:

new Component({ target: document.body })

But be aware that if you do not $destroy it yourself, you will end up with a memory leak.

When I do something like this, e.g. for notifications, I dispatch an event from the component that tells the calling code when the component can safely be destroyed. Something like:

const notification = new Notification({ target: document.body, ... });
notification.$on('close', () => notification.$destroy());
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!