mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-23 09:09:21 -05:00
use_storage SSR should return signal with defaults
This commit is contained in:
parent
861633dd1e
commit
bbebd8a67f
1 changed files with 12 additions and 1 deletions
|
@ -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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue