From 156e3c21bacbcf76659eca5e06ac16f92f03bd07 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 4 Mar 2022 14:31:04 -0500 Subject: [PATCH] feat: add split method to use_state --- packages/hooks/src/usestate.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/hooks/src/usestate.rs b/packages/hooks/src/usestate.rs index 6e8070191..d9530ee8e 100644 --- a/packages/hooks/src/usestate.rs +++ b/packages/hooks/src/usestate.rs @@ -285,6 +285,12 @@ impl UseState { RefMut::map(slot, |rc| Rc::get_mut(rc).expect("the hard count to be 0")) } + + /// Convert this handle to a tuple of the value and the handle itself. + #[must_use] + pub fn split(&self) -> (&T, &Self) { + (&self.current_val, self) + } } impl Clone for UseState {