fix: ssr mode input default value (#163)

This commit is contained in:
luoxiaozero 2024-04-13 18:17:54 +08:00 committed by GitHub
parent 4fe3dfd23f
commit aa793e16e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -140,6 +140,16 @@ pub fn Input(
}
};
let input_value: Option<String>;
#[cfg(feature = "ssr")]
{
input_value = Some(value.get_untracked());
}
#[cfg(not(feature = "ssr"))]
{
input_value = None;
}
#[cfg(debug_assertions)]
{
const INNER_ATTRS: [&str; 4] = ["type", "class", "disabled", "placeholder"];
@ -173,6 +183,7 @@ pub fn Input(
<input
{..attrs}
type=move || variant.get().as_str()
value=input_value
prop:value=move || {
value_trigger.track();
value.get()

View file

@ -23,7 +23,7 @@ where
T: Default + Clone + FromStr + ToString + 'static,
{
let input_value = create_rw_signal(String::default());
create_effect(move |prev| {
Effect::new_isomorphic(move |prev| {
value.with(|value| {
let value = value.to_string();
if let Some(prev) = prev {