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
sharedState.svelte.js
<script>
import { searchState} from './sharedState.svelte.js'

function handleClick(){
// uses the automatically created setter
searchState.text = "bicycles";
}

import { treeState } from './sharedState.svelte.js';
function handleSecondClick(){
treeState.push('🌳');
}
</script>

<h2>Object</h2>
<button onclick={handleClick}>Search for bicycles</button>
<div class="debug">{JSON.stringify({searchState})}</div>

<h2>Array</h2>
<button onclick={handleSecondClick}>Add tree</button>
<div class="debug">{JSON.stringify({treeState})}</div>


<style>
.debug{
margin:10px 0px;
background-color: lightcyan;
padding: 10px;
border:1px solid #999;
}
</style>
loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */