Component events
Components can also dispatch events. To do so, they must create an event dispatcher. Update Inner.svelte
:
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
function sayHello() {
dispatch('message', {
text: 'Hello!'
});
}
</script>
createEventDispatcher
must be called when the component is first instantiated — you can’t do it later inside e.g. asetTimeout
callback. This linksdispatch
to the component instance.