Skip to content

Signal<Vec<T>> -> Vec<Signal<T>> #3570

Closed Answered by ealmloff
cwahn asked this question in Q&A
Discussion options

You must be logged in to vote

This would require the mutable equivalent of Readable::map which doesn't exist yet. It seems fairly easy to add if you want to open an issue. With Writable::map you could do something like this:

fn List(list: Signal<Vec<i32>>) -> Element {
    rsx! {
        for index in 0..list.len() {
            // We can use the `map` method to provide a view into the single item in the list that the child component will render
            Item { item: list.map_mut(move |v| &v[index]) }
        }
    }
}

// The child component doesn't need to know that the mapped value is coming from a list
#[component]
fn Item(item: MappedSignalMut<i32>) -> Element {
    rsx! {
        button { onclick: |_| item += 1 }

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by cwahn
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants