I'm definitely very new to this so apologies if it's a simple answer.
// treatment.jsimport { writable } from 'svelte/store';export const treatment_uuid = writable('');export const treatment_name = writable('');export const error = writable('');
// +page.server.jsimport { supabase } from '$lib/supabaseClient';import { treatment_uuid, treatment_name, error } from '$stores/treatment';export async function load({ params }) { console.log('Params:', params); const { data, error: fetchError } = await supabase .from('treatments') .select('*') .eq('name', params.name) .single(); if (fetchError) { console.log('Error fetching data:', fetchError.message); error.set(fetchError.message); return { props: {} }; } console.log('Data fetched from Supabase:', data); treatment_uuid.set(data.uuid); treatment_name.set(data.name); console.log('Returning treatment_uuid:', data.uuid); console.log('Returning treatment_name:', data.name); return { props: {} };}
<!-- +page.svelte --><script> import { treatment_uuid, treatment_name, error } from '$stores/treatment'; import { get } from 'svelte/store'; console.log('Received props:', { treatment_uuid: get(treatment_uuid), treatment_name: get(treatment_name), error: get(error) });</script><main><h1>Treatment Details</h1> {#if $error}<p>Error: {$error}</p> {:else}<p>Treatment UUID: {$treatment_uuid}</p><p>Treatment Name: {$treatment_name}</p> {/if}</main>
This is the output I get and it shows the data for a second then goes to:
Params: { name: 'HIL-214' }Data fetched from Supabase: { uuid: 'd2397937-7a10-461c-a476-a7627965d2c1', name: 'HIL-214' }Returning treatment_uuid: d2397937-7a10-461c-a476-a7627965d2c1Returning treatment_name: HIL-214Received props: { treatment_uuid: 'd2397937-7a10-461c-a476-a7627965d2c1', treatment_name: 'HIL-214', error: ''}
Treatment DetailsTreatment UUID: (for a second the right UUID is here then blank)Treatment Name: (for a second the right name is here then blank)
Tried different methods to pass the data into it and most just have ''
or undefined
. This is the first the data has actually shown up even if just temporarily.