Repository navigation
Toggle is hard to achieve #2291
Madoshakalaka
started this conversation in
General
Replies: 3 comments 5 replies
|
@Madoshakalaka With the power of hooks its realy easy to do that yourself: pub fn use_toggle<F>(init_fn: F) -> (bool,Callback<()>)
where
F: FnOnce() -> bool,
{
let value_handle = use_state_eq(init_fn);
let value = *value_handle;
let toggle = Callback(move |_| {
value_handle.set(!value);
});
(value,toggle)
} |
3 replies
|
The #[derive(PartialEq, Default)]
struct State {
inner: bool
}
impl Reducible for State {
type Action = ();
fn reduce(self: Rc<Self>, _action: Self::Action) -> Rc<Self> {
State { inner: !self.inner }.into()
}
}
let on_or_off = use_reducer_eq(State::default); |
2 replies
|
Try use_bool_toggle and use_toggle from yew_hooks: https://github.com/jetli/yew-hooks |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
correct me if I am wrong: this is the minimum code to achieve a toggling state:
a
use_toggle()would be niceAll reactions