Skip to content

Svelte bind equivalent #337

Answered by gbj
lebenoa asked this question in Q&A
Jan 18, 2023 · 1 comments · 8 replies
Discussion options

You must be logged in to vote

No worries. This framework is fairly different from React but quite similar to SolidJS, so you may have more luck there. In either case, you want to look up React or Solid "controlled components" and "uncontrolled components" for patterns.

let (name, set_name) = create_signal(cx, "gbj".to_string());
view! { cx,
  <input type="text"
    // updates the `value` property in the DOM reactively to match `name`
    prop:value=name
    // event_target_value is the equiv. of JS event.target.value
    // just a helper to smooth out some Rust/JS type awkwardness
    on:input=move |ev| set_name(event_target_value(&name))
  />
}

The equivalent goes for prop:checked and event_target_checked on a checkbox.

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@lebenoa
Comment options

@gbj
Comment options

gbj Jan 19, 2023
Maintainer

@lebenoa
Comment options

@gbj
Comment options

gbj Jan 19, 2023
Maintainer

@lebenoa
Comment options

Answer selected by lebenoa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants