-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Portal in examples section #4237
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
Comments
Could be a bit simpler <script>
import { onMount } from 'svelte';
let ref;
onMount(() => document.body.appendChild(ref));
</script>
<div class="portal" bind:this={ref}>
<slot></slot>
</div> |
@PatrickG, You forgot |
You don't need the onDestroy. Svelte removes the element anyway. <script>
let ref;
$: ref && document.body.appendChild(ref);
</script>
<div class="portal" bind:this={ref}>
<slot></slot>
</div> |
Ok. And what If I need to "append" it not on body but in another component? For example in I'm using the And sometimes (based on routing or custom logic, maybe behind a Svelte I opened this issue to address this "situation" "the right way". Your hint? |
That's not the right place to ask this kind of questions, you should discuss this on discord. <script>
// App.svelte
import Whatever from './Whatever.svelte';
import Sidebar from './Sidebar.svelte';
</script>
<Sidebar Child={Whatever} /> <script>
// Sidebar.svelte
export Child = undefined;
</script>
{#if Child}
<Child />
{/if} |
@PatrickG this is not what I'm asking, but it's ok. Talking about the The guy here is using the Is it wrong? |
It's not wrong, just another way. |
There's a typo in your code, a double Can you explain it better the magic of this line? $: ref && document.body.appendChild(ref); I can open a PR for this example with your amazing code. |
You better ask such questions on discord. |
This should absolutely be in the svelte examples. https://svelte.dev/repl/48afb902e70a4349bd0bfbe69d514df1?version=3.17.2 here is a repl |
Can we add this Portal repl in the examples section?
#3088 (comment)
Copyright @ThomasJuster.
The text was updated successfully, but these errors were encountered: