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
store.js
<script>
import { onMount } from 'svelte';
import { searchTerm, people } from './store';

let timer;
// debouncing is always a good idea :]
function handleKeyup(event){
clearTimeout(timer);
timer = setTimeout(() => searchTerm.set(event.target.value), 500);
}
</script>

<h1>Search a user by name (try Clementine)</h1>

<input type="text" value={$searchTerm} on:keyup={handleKeyup} />
<p>
Try deleting the contents of the input and putting the same text again. It will get the cached result instead of making a second API call :]
</p>

{#if $searchTerm}
{#await $people}
<p>Searching...</p>
{:then $people}
{#each $people as person}
<p>Name: {person.name}</p>
{/each}
{:catch $people}
<p>ohno, something wrong isn't right! here's ther error:</p>
<p>{JSON.stringify($people)}</p>
{/await}
{/if}

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