use std::{cell::RefCell, rc::Rc}; use crate::use_state; use crate::UseFutureDep; use dioxus_core::{ScopeState, UiEvent}; use std::future::Future; pub fn use_callback + 'static>( cx: &ScopeState, // g: G, f: impl FnMut(I, G::Out) -> F, ) -> &UseCallback where G::Out: 'static, I: 'static, { cx.use_hook(|_| { // UseCallback { f: todo!(), f2: Box::new(|f| {}), } }) } pub struct UseCallback { f: Rc>>>, f2: Box, // f: Rc>>>, } impl std::ops::Deref for UseCallback { type Target = dyn Fn(I); fn deref(&self) -> &Self::Target { &self.f2 } } trait MyThing {} impl MyThing for Box {} impl MyThing for Box {} #[test] fn demo() { use dioxus_core::prelude::*; fn example(cx: Scope) -> Element { let (name, _) = use_state(&cx, || 0); let (age, _) = use_state(&cx, || 0); let onsubmit = use_callback(&cx, (name,), |event: (), (name,)| async move { // }); let onsubmit = use_callback(&cx, (name,), my_callback); async fn my_callback(event: UiEvent<()>, name: (i32,)) { // } let onsubmit = use_callback(&cx, name, my_callback2); async fn my_callback2(event: UiEvent<()>, name: i32) { // } None } }