Skip to content

Commit

Permalink
Remove returned Rc in use_state
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jan 20, 2024
1 parent 21ab792 commit aa13648
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 4 additions & 2 deletions crates/concoct/src/hook/use_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use std::{cell::RefCell, rc::Rc};
/// let (count, set_count) = use_state(|| 0);
/// assert_eq!(count, 0);
/// ```
pub fn use_state<T: Clone + 'static>(make_value: impl FnOnce() -> T) -> (T, Rc<dyn Fn(T)>) {
pub fn use_state<T: Clone + 'static>(
make_value: impl FnOnce() -> T,
) -> (T, impl Fn(T) + Clone + 'static) {
let cell = use_ref(|| RefCell::new(make_value()));
let getter = cell.borrow().clone();

Expand All @@ -30,5 +32,5 @@ pub fn use_state<T: Clone + 'static>(make_value: impl FnOnce() -> T) -> (T, Rc<d
}
};

(getter, Rc::new(setter))
(getter, setter)
}
7 changes: 1 addition & 6 deletions crates/concoct/src/view.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use rustc_hash::FxHasher;

use crate::{body::Empty, Body};
use std::{
hash::{Hash, Hasher},
rc::Rc,
};
use std::rc::Rc;

pub trait View: 'static {
fn body(&self) -> impl Body;
Expand Down

0 comments on commit aa13648

Please sign in to comment.