@@ -31,21 +31,14 @@ ds::comp! {
3131 let x = ds :: use_state :: <f64 >(|| 0.0 );
3232 let button = ds :: use_fixture <Option <UiComponent >>(|| None );
3333
34- // For the React.js familiar, use_effect!() here acts
35- // different; by default, the dependencies list is "empty".
36- //
37- // Dependencies are not auto tracked, even because
38- // not just "states" have to be tracked, but also
39- // parameters and derived.
34+ // Effect
4035 ds :: use_effect! ({
4136 (* button ). unwrap (). focus ();
42- // cleanup (optional)
43- || {}
4437 });
4538
4639 ds :: xn! {
4740 <w : VGroup s : color = " orange" >
48- // Style block scoped to that VGroup tag.
41+ // Style sheet scoped to that VGroup tag.
4942 <w : Style >
5043 r ### "
5144 :host {
@@ -65,7 +58,7 @@ ds::comp! {
6558}
6659```
6760
68- ## Style blocks
61+ ## & lt ; w : Style & gt ; tag
6962
7063A component tag accepts ` <w:Style> ` tags only if it defines a ` stylesheets: Option<whack::ds::StyleSheets> ` field.
7164
@@ -93,7 +86,7 @@ The creator may spread existing style sheets:
9386
9487``` rust
9588<w : Style extend = {stylesheets }/ >
96- // ` stylesheets: Option<whack::ds::StyleSheets>
89+ // stylesheets: Option<whack::ds::StyleSheets>
9790```
9891
9992The creator may pass a ` HashMap<String, String> ` as arguments to a style sheet...
@@ -154,6 +147,8 @@ bind={|val| {
154147
155148## Fields
156149
150+ Component fields are the parameters it receives in the ` whack::ds::comp! ` macro.
151+
157152### String
158153
159154A field
@@ -269,4 +264,52 @@ Specifying a default value for a field prevents the program from panicking for o
269264``` rust
270265#[default = v]
271266x : T ,
267+ ```
268+
269+ ## Hooks
270+
271+ ` use_state(...) ` , ` use_fixture(...) ` , ` use_context(...) ` and ` use_effect!(...) ` are examples of built-in hooks.
272+
273+ Hooks must only appear at the top-level of a WhackDS component, and must not be run conditionally.
274+
275+ ## Effects
276+
277+ The ` use_effect! ` hook (effect) is used for either:
278+
279+ - Running code when component mounts and unmounts (the cleanup)
280+ - Running code when a list of values change (e.g. states, derived values and parameters)
281+
282+ The effect must explicitly state its dependencies (i.e. it should run when a specific value changes), or it has no dependencies by default.
283+
284+ Here are some examples:
285+
286+ ``` rust
287+ whack :: ds :: use_effect! ({
288+ // runs whenever component mounts
289+ });
290+
291+ whack :: ds :: use_effect! ({
292+ // runs whenever component mounts
293+ // (...)
294+
295+ || {
296+ // cleanup.
297+ // runs when component unmounts
298+ }
299+ });
300+
301+ whack :: ds :: use_effect! ({
302+ // runs whenever the `x` state changes
303+ }, [x . get ()]);
304+
305+ whack :: ds :: use_effect! ({
306+ // runs whenever the `variant` parameter changes
307+ // (...)
308+
309+ || {
310+ // cleanup.
311+ // runs either before re-running this effect,
312+ // or when component is unmounted.
313+ }
314+ }, [variant ]);
272315```
0 commit comments