Svelte · Middle · Question 52 of 75
How can a component expose methods to its parent?
<!-- Dialog.svelte -->
<script>
let dialog;
export function open() { dialog.showModal(); }
</script>
<dialog bind:this={dialog}>...</dialog>
<!-- Parent -->
<Dialog bind:this={d} />
<button onclick={() => d.open()}>Open</button>- ✓Correct answer: Export a function from
<script>and call it via abind:thisreference - 2Through
$props() - 3It's not possible in Svelte 5
Explanation
Exported functions and constants become the component's instance API. Prefer props for data flow and keep this for imperative actions.