浏览代码

feat: add split method to use_state

Jonathan Kelley 3 年之前
父节点
当前提交
156e3c21ba
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      packages/hooks/src/usestate.rs

+ 6 - 0
packages/hooks/src/usestate.rs

@@ -285,6 +285,12 @@ impl<T: Clone> UseState<T> {
 
         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<T: 'static> Clone for UseState<T> {