@svuick/events
Installation
npm i @svuick/events
What is this?
This package enables svelte developers to pass events through components with ease.
The main benefit is not having to forward events up the component tree.
Usage
src/lib/MyComponent.svelte
<script lang="ts">
import { createEventContext } from '@svuick/events'
import MyNestedComponent from './MyNestedComponent';
const events = createEventContext();
let value = 0;
events.on('update', newValue => value = newValue);
</script>
<MyNestedComponent/>
{value}
src/lib/MyComponent.svelte
<script lang="ts">
import { getEventContext } from '@svuick/events'
const events = getEventContext();
let value = 0;
function handleClick() {
events.emit('update', value);
}
</script>
<input type="number" bind:value={value}/>
<button on:click={handleClick}>Send!</button>