#![allow(clippy::needless_update)] use appy::{components::*, hooks::*, types::*, *}; use std::rc::Rc; #[derive(Clone)] enum Action { Add, Sub, } #[derive(Clone)] struct AppState { v: i32, } impl AppState { fn reducer(&self, a: Action) -> Self { match a { Action::Add => Self { v: self.v + 1 }, Action::Sub => Self { v: self.v - 1 }, } } } #[derive_component(Default, ComponentBuilder, SnakeFactory)] pub struct TextButton { text: String, on_click: Option>, } #[function_component] fn _text_button(props: TextButton) -> Elements { let hover_state = use_hover_state_ref(); let c = match *hover_state { HoverState::Normal => 0x808080, HoverState::Active => 0x404040, HoverState::Hover => 0xc0c0c0, }; apx! { } } #[main_window] pub fn app() -> Elements { let state = use_reducer(AppState::reducer, || AppState { v: 1 }); let s = format!("Value: {}", (*state).v); apx! { } }