I have a problem in which I have scenario such that recursively same component I want to call in svelte component. They should work like parent and child such like recursively function call.
I have search it over internet and svelte website, but haven’t get proper answer?
Is there any another way in svelte and sveltekit for doing that?
I have tried this in the component but at last there is issue of importing the component.
I want any solution for that
- importing the component
- Any other way to do that
1
You should be able to import the current file from the current file.
I.e.
<!-- Component.svelte -->
<script>
import Component from './Component.svelte';
</script>
<Component />
REPL example
There also is a special <svelte:self>
tag, which serves the same purpose but given that self-referential imports should be supported, it could potentially be removed in the future. It also has no proper type checking (see this issue).