pub fn use_radio<Value, Channel>(channel: Channel) -> Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Value: 'static,Expand description
Subscribe to the global state for a specific channel.
Returns a Radio handle that allows reading and writing the state.
The current component will re-render whenever the specified channel is notified.
This hook must be called within a component that has access to a RadioStation
(either through use_init_radio_station or use_share_radio).
§Example
ⓘ
fn app() -> impl IntoElement {
use_init_radio_station::<AppState, AppChannel>(AppState::default);
rect().child(Counter {})
}
#[derive(PartialEq)]
struct Counter {}
impl Component for Counter {
fn render(&self) -> impl IntoElement {
let mut radio = use_radio(AppChannel::Count);
rect()
.child(label().text(format!("Count: {}", radio.read().count)))
.child(
Button::new()
.on_press(move |_| radio.write().count += 1)
.child("+"),
)
}
}