Skip to content

Starting with Yew: Are all these clones needed for a callback? #3535

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

You must be logged in to vote

Nevermind I think I got it. I shouldn't have read the getting started page, but the tutorial, my bad.

Resulting code:

use crate::models::task::Task;
use uuid::Uuid;
use yew::prelude::*;

#[derive(PartialEq, Properties)]
pub struct TaskListProps {
    pub tasks: Vec<Task>,
    pub onselect: Callback<Uuid, ()>,
    #[prop_or_default]
    pub selected_task: Option<Uuid>,
}

#[function_component]
pub fn TaskList(props: &TaskListProps) -> Html {
    let TaskListProps {
        tasks,
        selected_task,
        onselect,
    } = props;
    let selected_task = use_state(|| selected_task.clone());

    let onselect = {
        let selected_task = selected_task.clone();
        onselect.reform(m…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ranile
Comment options

Answer selected by koenichiwa
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