Skip to content

Conversation

@ealmloff
Copy link
Member

Removes writable from use_memo and replaces it with a derived signal hook. Note the new hook does not memoize the value or rerun immediately which makes it possible to return a normal signal while still filling the signal derived from reactive props use case

#[derive(Routable, Clone)]
enum Route {
    // When you first navigate to this route, initial_count will be used to set the value of
    // the count signal
    #[route("/:initial_count")]
    Counter { initial_count: u32 },
}

#[component]
fn Counter(initial_count: ReadSignal<u32>) -> Element {
    // The count will reset to the value of the prop whenever the prop changes
    let mut count = use_derived_signal(move || initial_count());

    rsx! {
        button {
            onclick: move |_| count += 1,
            "{count}"
        }
        Link {
            // Navigating to this link will change the initial_count prop to 10. Note, this
            // only updates the props, the component is not remounted
            to: Route::Counter { initial_count: 10 },
            "Go to initial count 10"
        }
    }
}

Closes #4800

@ealmloff ealmloff requested a review from a team as a code owner October 21, 2025 17:52
@ealmloff ealmloff added bug Something isn't working enhancement New feature or request hooks Changes to built-in hook package signals Related to the signals crate labels Oct 21, 2025
@ealmloff ealmloff added the breaking This is a breaking change label Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking This is a breaking change bug Something isn't working enhancement New feature or request hooks Changes to built-in hook package signals Related to the signals crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Writable memos break consistency guarantees

1 participant