Remove argument from use_hook closure (#496)

Also; update docs for said function
This commit is contained in:
Reinis Mazeiks authored and GitHub committed 2022-07-11 15:50:56 -04:00
1 parent 6ea076fa7f
commit d734dc5b46
29 files changed
+53 -55

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ fn test_borrowed_state() {
}
fn Parent(cx: Scope) -> Element {
let value = cx.use_hook(|_| String::new());
let value = cx.use_hook(|| String::new());
cx.render(rsx! {
div {
+1 -1
View File
@@ -20,7 +20,7 @@ fn new_dom<P: 'static + Send>(app: Component<P>, props: P) -> VirtualDom {
#[test]
fn test_early_abort() {
const app: Component = |cx| {
let val = cx.use_hook(|_| 0);
let val = cx.use_hook(|| 0);
*val += 1;
+3 -3
View File
@@ -34,7 +34,7 @@ fn manual_diffing() {
#[test]
fn events_generate() {
fn app(cx: Scope) -> Element {
let count = cx.use_hook(|_| 0);
let count = cx.use_hook(|| 0);
let inner = match *count {
0 => {
@@ -77,7 +77,7 @@ fn events_generate() {
#[test]
fn components_generate() {
fn app(cx: Scope) -> Element {
let render_phase = cx.use_hook(|_| 0);
let render_phase = cx.use_hook(|| 0);
*render_phase += 1;
cx.render(match *render_phase {
@@ -171,7 +171,7 @@ fn components_generate() {
#[test]
fn component_swap() {
fn app(cx: Scope) -> Element {
let render_phase = cx.use_hook(|_| 0);
let render_phase = cx.use_hook(|| 0);
*render_phase += 1;
cx.render(match *render_phase {
+6 -6
View File
@@ -22,7 +22,7 @@ fn new_dom<P: 'static + Send>(app: Component<P>, props: P) -> VirtualDom {
#[test]
fn test_memory_leak() {
fn app(cx: Scope) -> Element {
let val = cx.use_hook(|_| 0);
let val = cx.use_hook(|| 0);
*val += 1;
@@ -30,7 +30,7 @@ fn test_memory_leak() {
return None;
}
let name = cx.use_hook(|_| String::from("asd"));
let name = cx.use_hook(|| String::from("asd"));
cx.render(rsx!(
div { "Hello, world!" }
@@ -79,7 +79,7 @@ fn test_memory_leak() {
#[test]
fn memo_works_properly() {
fn app(cx: Scope) -> Element {
let val = cx.use_hook(|_| 0);
let val = cx.use_hook(|| 0);
*val += 1;
@@ -87,7 +87,7 @@ fn memo_works_properly() {
return None;
}
let name = cx.use_hook(|_| String::from("asd"));
let name = cx.use_hook(|| String::from("asd"));
cx.render(rsx!(
div { "Hello, world! {name}" }
@@ -192,7 +192,7 @@ fn free_works_on_root_hooks() {
}
fn app(cx: Scope) -> Element {
let name = cx.use_hook(|_| Droppable(String::from("asd")));
let name = cx.use_hook(|| Droppable(String::from("asd")));
rsx!(cx, div { "{name.0}" })
}
@@ -204,7 +204,7 @@ fn free_works_on_root_hooks() {
fn old_props_arent_stale() {
fn app(cx: Scope) -> Element {
dbg!("rendering parent");
let cnt = cx.use_hook(|_| 0);
let cnt = cx.use_hook(|| 0);
*cnt += 1;
if *cnt == 1 {
+1 -1
View File
@@ -36,7 +36,7 @@ fn swap_test() {
struct MySharedState(&'static str);
fn app(cx: Scope) -> Element {
let val = cx.use_hook(|_| 0);
let val = cx.use_hook(|| 0);
*val += 1;
cx.provide_context(Rc::new(MySharedState("world!")));