use_storage SSR should return signal with defaults

This commit is contained in:
Joshua McQuistan 2023-10-27 14:50:29 +01:00
parent 861633dd1e
commit bbebd8a67f

View file

@ -2,6 +2,7 @@ use crate::{
core::{MaybeRwSignal, StorageType}, core::{MaybeRwSignal, StorageType},
use_event_listener_with_options, use_window, UseEventListenerOptions, use_event_listener_with_options, use_window, UseEventListenerOptions,
}; };
use cfg_if::cfg_if;
use leptos::*; use leptos::*;
use std::{rc::Rc, str::FromStr}; use std::{rc::Rc, str::FromStr};
use thiserror::Error; use thiserror::Error;
@ -80,7 +81,17 @@ where
T: Clone + PartialEq, T: Clone + PartialEq,
C: Codec<T>, C: Codec<T>,
{ {
// TODO ssr cfg_if! { if #[cfg(feature = "ssr")] {
let (data, set_data) = create_signal(None);
let set_value = move |value: Option<T>| {
set_data.set(value);
};
let value = create_memo(move |_| data.get().unwrap_or_default());
return (value, set_value);
} else {
// Continue
}}
let UseStorageOptions { let UseStorageOptions {
codec, codec,
on_error, on_error,