Skip to content

Commit 2367f78

Browse files
dtoniolohecrj
authored andcommitted
Document how the state of a Component can be managed
1 parent e9e8e83 commit 2367f78

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

widget/src/lazy/component.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ use std::rc::Rc;
3131
///
3232
/// Additionally, a [`Component`] is capable of producing a `Message` to notify
3333
/// the parent application of any relevant interactions.
34+
///
35+
/// # State
36+
/// A component can store its state in one of two ways: either as data within the
37+
/// implementor of the trait, or in a type [`State`][Component::State] that is managed
38+
/// by the runtime and provided to the trait methods. These two approaches are not
39+
/// mutually exclusive and have opposite pros and cons.
40+
///
41+
/// For instance, if a piece of state is needed by multiple components that reside
42+
/// in different branches of the tree, then it's more convenient to let a common
43+
/// ancestor store it and pass it down.
44+
///
45+
/// On the other hand, if a piece of state is only needed by the component itself,
46+
/// you can store it as part of its internal [`State`][Component::State].
3447
#[cfg(feature = "lazy")]
3548
#[deprecated(
3649
since = "0.13.0",

0 commit comments

Comments
 (0)