Skip to content

callback not rendering when vector is passed as dep #3307

Open
@t0mpl

Description

@t0mpl

Hi,
I'm trying to pass a state as dependency for a callback function, this state is a vector of struct, I get no compiler error, but the callback never update when the vector state is mutated.

Am I doing something wrong or is there a workaround to this problem?

thanks for your help.

let messages_handler: yew::UseStateHandle<Vec<Message>> = use_state(|| {
        vec![]
    });
    let messages_handler_value = (*messages_handler).clone();

    let on_new_message: Callback<Message, ()> = {
        let messages_handler = messages_handler.clone();
        let messages_handler_value = messages_handler_value.clone();

        use_callback(
            move |message: Message, messages_handler_value| {
                let mut messages_handler_value = messages_handler_value.clone();
                messages_handler_value.push(message);

                messages_handler.set(messages_handler_value);
            },
            messages_handler_value.clone(),
        )
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions