|
@@ -272,13 +272,13 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
|
|
/// main.rs:
|
|
/// main.rs:
|
|
/// ```rust, no_run
|
|
/// ```rust, no_run
|
|
/// # use dioxus::prelude::*;
|
|
/// # use dioxus::prelude::*;
|
|
- /// # fn Child() -> Element { todo!() }
|
|
|
|
|
|
+ /// # fn Child() -> Element { unimplemented!() }
|
|
/// fn app() -> Element {
|
|
/// fn app() -> Element {
|
|
/// let signal = use_context_provider(|| Signal::new(0));
|
|
/// let signal = use_context_provider(|| Signal::new(0));
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// // We want to log the value of the signal whenever the app component reruns
|
|
/// // We want to log the value of the signal whenever the app component reruns
|
|
/// println!("{}", *signal.read());
|
|
/// println!("{}", *signal.read());
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// rsx! {
|
|
/// rsx! {
|
|
/// button {
|
|
/// button {
|
|
/// // If we don't want to rerun the app component when the button is clicked, we can use write_silent
|
|
/// // If we don't want to rerun the app component when the button is clicked, we can use write_silent
|
|
@@ -294,7 +294,7 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
|
|
/// # use dioxus::prelude::*;
|
|
/// # use dioxus::prelude::*;
|
|
/// fn Child() -> Element {
|
|
/// fn Child() -> Element {
|
|
/// let signal: Signal<i32> = use_context();
|
|
/// let signal: Signal<i32> = use_context();
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// // It is difficult to tell that changing the button to use write_silent in the main.rs file will cause UI to be out of sync in a completely different file
|
|
/// // It is difficult to tell that changing the button to use write_silent in the main.rs file will cause UI to be out of sync in a completely different file
|
|
/// rsx! {
|
|
/// rsx! {
|
|
/// "{signal}"
|
|
/// "{signal}"
|
|
@@ -308,13 +308,13 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
|
|
/// main.rs:
|
|
/// main.rs:
|
|
/// ```rust, no_run
|
|
/// ```rust, no_run
|
|
/// # use dioxus::prelude::*;
|
|
/// # use dioxus::prelude::*;
|
|
- /// # fn Child() -> Element { todo!() }
|
|
|
|
|
|
+ /// # fn Child() -> Element { unimplemented!() }
|
|
/// fn app() -> Element {
|
|
/// fn app() -> Element {
|
|
/// let mut signal = use_context_provider(|| Signal::new(0));
|
|
/// let mut signal = use_context_provider(|| Signal::new(0));
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// // We want to log the value of the signal whenever the app component reruns, but we don't want to rerun the app component when the signal is updated so we use peek instead of read
|
|
/// // We want to log the value of the signal whenever the app component reruns, but we don't want to rerun the app component when the signal is updated so we use peek instead of read
|
|
/// println!("{}", *signal.peek());
|
|
/// println!("{}", *signal.peek());
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// rsx! {
|
|
/// rsx! {
|
|
/// button {
|
|
/// button {
|
|
/// // We can use write like normal and update the child component automatically
|
|
/// // We can use write like normal and update the child component automatically
|
|
@@ -330,7 +330,7 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
|
|
/// # use dioxus::prelude::*;
|
|
/// # use dioxus::prelude::*;
|
|
/// fn Child() -> Element {
|
|
/// fn Child() -> Element {
|
|
/// let signal: Signal<i32> = use_context();
|
|
/// let signal: Signal<i32> = use_context();
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// rsx! {
|
|
/// rsx! {
|
|
/// "{signal}"
|
|
/// "{signal}"
|
|
/// }
|
|
/// }
|
|
@@ -550,7 +550,7 @@ struct Counts {
|
|
|
|
|
|
fn app() -> Element {
|
|
fn app() -> Element {
|
|
let mut counts = use_signal(|| Counts { count1: 0, count2: 0 });
|
|
let mut counts = use_signal(|| Counts { count1: 0, count2: 0 });
|
|
-
|
|
|
|
|
|
+
|
|
use_effect(move || {
|
|
use_effect(move || {
|
|
// This effect both reads and writes to counts
|
|
// This effect both reads and writes to counts
|
|
counts.write().count1 = counts().count2;
|
|
counts.write().count1 = counts().count2;
|