Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jul 14, 2024
1 parent b765f1a commit ea5bcb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [Components](./learn/components.md)
- [Hooks](./learn/hooks.md)
- [State Management](./learn/state_management.md)
- [Local Signals](./learn/state_management/signals.md)
- [Signals](./learn/state_management/signals.md)
- [Global Signals](./learn/state_management/global_signals.md)
- [Dioxus Hooks](./learn/dioxus_hooks.md)
- [Context](./learn/state_management/context.md)
Expand Down
17 changes: 14 additions & 3 deletions book/src/learn/state_management/signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ Example:
```rs
fn app() -> Element {
let mut count = use_signal(|| 0);
// The closure passed to `use_signal` will be called only the first time this component function runs, it will return the initial value for the Signal. This closure is to prevent having to create the initial value every time the component runs again, as it is only needed the first time.
// The closure passed to `use_signal` will be called only
// the first time this component function runs,
// it will return the initial value for the Signal.
// This closure is to prevent having to create the initial value
// every time the component runs again, as it is only needed the first time.

let onclick = move |_| {
count += 1; // Shorthand for count.write() += 1;
// The moment the signal is mutated it will notify all the components that have a read subscription to this signal (in this case, only `app`) that there has been a change. When that happens they will all run their functions again and thus producing the new UI.
// The moment the signal is mutated it will notify
// all the components that have a read subscription
// to this signal (in this case, only `app`)
// that there has been a change.
// When that happens they will all run
// their functions again and thus producing the new UI.
};

rsx!(
label {
onclick,
"{count}"
// Because the signal is being read here, everytime that it gets mutated this component will rerun as it received a read subscription.
// Because the signal is being read here,
// everytime that it gets mutated this component
// will rerun as it received a read subscription.
// It is the same as using "{count.read()}".
}
)
Expand Down

0 comments on commit ea5bcb3

Please sign in to comment.