Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Make DOM live update with SvelteKit and Supabase

$
0
0

I am using SvelteKit with Supabase. Whenever the form is submitted I would like to see the DOM live update. However, it takes a refresh to see the changes.How would I live update the DOM whenever a new row is inserted into the table?

<script>    import { supabase } from '$lib/supabaseClient'    const getData = async function() {        const { data, error } = await supabase        .from('scores')        .select('*')        return data    }    let newRowName = '';    let newRowScore = 0;    const postData = async function(nameVal, scoreVal) {        const { data, error } = await supabase        .from('scores')        .insert([{ name: nameVal, score: scoreVal }])    }</script>{#await getData()}<p>Waiting...</p>{:then data}    {#each data as singleData}<p>{singleData.name}: {singleData.score}</p>    {/each}{:catch error}<p>Error occured</p>{/await}<form on:submit|preventDefault="{() => postData(newRowName, newRowScore)}"><label for="name">Name:</label><input type="text" id='name' bind:value='{newRowName}' required /><label for="score">Score:</label><input type="number" id='score' bind:value='{newRowScore}' required /><button>Add row</button></form>

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>