Skip to main content
Basic Svelte
Introduction
Reactivity
Props
Logic
Events
Bindings
Classes and styles
Actions
Transitions
Advanced Svelte
Advanced reactivity
Reusing content
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
Forms
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Hooks
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion

You can pass event handlers to components like any other prop. In Stepper.svelte, add increment and decrement props...

Stepper
<script>
	let { increment, decrement } = $props();
</script>
<script lang="ts">
	let { increment, decrement } = $props();
</script>

...and wire them up:

Stepper
<button onclick={decrement}>-1</button>
<button onclick={increment}>+1</button>

In App.svelte, define the handlers:

<Stepper
	increment={() => value += 1}
	decrement={() => value -= 1}
/>

Edit this page on GitHub

1
2
3
4
5
6
7
8
9
10
<script>
	import Stepper from './Stepper.svelte';
 
	let value = $state(0);
</script>
 
<p>The current value is {value}</p>
 
<Stepper />