Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
Child.svelte
store.js
<script>
import { counter } from './store';
import Child from './Child.svelte';

console.log('With love, Sony AK <sony@sony-ak.com>. GitHub https://github.com/sonyarianto');
</script>

<h1>Counter on parent component is {$counter}.</h1>

<Child />

<br/>

<button on:click={() => $counter--}>I am a button on parent component to decrease the global state of counter</button>
<br/>
<button on:click={() => counter.set(0)}>Reset the global state counter</button>

<h3>When you click the button it will sync all counter anywhere we need it.</h3>

<pre>
- Where is the store defined? Just open store.js
- What is the $ in front of counter? ($counter) is the auto-subscribe magic in Svelte
</pre>

loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */