← All Workshops
Intro to Dioxus 0.7
Step 3 / 6
Reactive State with Signals
Signals are the reactive primitive in Dioxus 0.7. Use `use_signal` to create
local state. Reading a signal in your component automatically subscribes to
changes — no manual dependency tracking needed.
src/main.rs
#[component]
fn Counter() -> Element {
let mut count = use_signal(|| 0);
rsx! {
p { "Count: {count}" }
button {
onclick: move |_| *count.write() += 1,
"Increment"
}
button {
onclick: move |_| *count.write() -= 1,
"Decrement"
}
}
}
Watch in browser
dx serve --openStep 3 / 6