use_storage now always writes the default value to storage if the key doesn’t exist

This commit is contained in:
Marc-Stefan Cassola 2024-07-16 19:57:30 +01:00 committed by GitHub
parent 85376f8165
commit c26a96d8a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -272,13 +272,6 @@ where
} }
}; };
// Fetch initial value
if delay_during_hydration && leptos::leptos_dom::HydrationCtx::is_hydrating() {
request_animation_frame(fetch_from_storage.clone());
} else {
fetch_from_storage();
}
// Fires when storage needs to be fetched // Fires when storage needs to be fetched
let notify = create_trigger(); let notify = create_trigger();
@ -329,6 +322,13 @@ where
); );
} }
// Fetch initial value
if delay_during_hydration && leptos::leptos_dom::HydrationCtx::is_hydrating() {
request_animation_frame(fetch_from_storage.clone());
} else {
fetch_from_storage();
}
if listen_to_storage_changes { if listen_to_storage_changes {
let check_key = key.as_ref().to_owned(); let check_key = key.as_ref().to_owned();
// Listen to global storage events // Listen to global storage events