sveltekit-realtime-chat-sample Svelte Themes

Sveltekit Realtime Chat Sample

A minimal real-time chat in 8 lines of svelte using jsdb and sveltekit.

A minimal real-time chat in 7 lines of svelte using https://javascriptdb.com and https://kit.svelte.dev/

Try it live at https://chat.javascriptdb.com

<script>
    import {DatabaseArray} from "@jsdb/sdk";
    const msgs = new DatabaseArray('msgs');
    const lastMinuteMessages = msgs.filter(message => message.date > (Date.now() - 60*1000));
</script>
<input on:keyup={e => e.key==='Enter' && msgs.push({text: e.target.value, date: Date.now()}) && (e.target.value = '')}/>
{#each $lastMinuteMessages || [] as msg} <div>{msg.text}</div> {/each}

Extracted from /src/routes/index.svelte

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes