Skip to content

How to use values of signals in onclick of a button #3079

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

You must be logged in to vote

this will solve

#[component]
fn FriendRequestItem(sender: String) -> Element {
    rsx! {
        div { "{sender}" }
        button {
            onclick: move |_| {
                println!("Accepting friend request from {}", sender);
            },
            "Accept"
        }
    }
}

#[component]
pub(crate) fn CAcceptFriendWindow() -> Element {
    let friend_requests = use_resource(move || get_friend_requests());

    match &*friend_requests.read_unchecked() {
        Some(Ok(list)) => {
            rsx! {
                div {
                    for sender in list {
                        FriendRequestItem { sender: sender }
                    }
                }
            }

Replies: 1 comment

Comment options

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