You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a functional component you can use the **useEffect** hook as normal.
572
572
573
+
## Deferring model updates and messages
574
+
575
+
Sometimes you want to always dispatch a message or update the model in all cases. You can use the `defer` function from the `options` parameter to do this. The `options` parameter is the fourth parameter of the `update` function.
576
+
577
+
Without the `defer` function, you would have to return the model and the command in all cases:
The `defer` function can be called multiple times. Model updates and commands are then aggregated. Model updates by the return value overwrite the deferred model updates, while deferred messages are dispatched after the returned messages.
614
+
615
+
## Call back parent components
616
+
617
+
Since each component has its own model and messages, communication with parent components is done via callback functions.
618
+
619
+
To inform the parent component about some action, let's say to close a dialog form, you do the following:
620
+
621
+
1. Create a message
622
+
623
+
```tsDialog.ts
624
+
exporttype Message =
625
+
...
626
+
| { name: "close" }
627
+
...
628
+
629
+
exportconst Msg = {
630
+
...
631
+
close: ():Message=> ({ name: "close" }),
632
+
...
633
+
}
634
+
```
635
+
636
+
1. Define a callback function property in the **Props**:
637
+
638
+
```tsDialog.ts
639
+
exporttype Props = {
640
+
onClose: () =>void,
641
+
};
642
+
```
643
+
644
+
1. Handle the message and call the callback function:
Sometimes you want to always dispatch a message or update the model in all cases. You can use the `defer` function from the `options` parameter to do this. The `options` parameter is the fourth parameter of the `update` function.
805
-
806
-
Without the `defer` function, you would have to return the model and the command in all cases:
The `defer` function can be called multiple times. Model updates and commands are then aggregated. Model updates by the return value overwrite the deferred model updates, while deferred messages are dispatched after the returned messages.
843
-
844
-
## Call back parent components
845
-
846
-
Since each component has its own model and messages, communication with parent components is done via callback functions.
847
-
848
-
To inform the parent component about some action, let's say to close a dialog form, you do the following:
849
-
850
-
1. Create a message
851
-
852
-
```tsDialog.ts
853
-
exporttype Message =
854
-
...
855
-
| { name: "close" }
856
-
...
857
-
858
-
exportconst Msg = {
859
-
...
860
-
close: ():Message=> ({ name: "close" }),
861
-
...
862
-
}
863
-
```
864
-
865
-
1. Define a callback function property in the **Props**:
866
-
867
-
```tsDialog.ts
868
-
exporttype Props = {
869
-
onClose: () =>void,
870
-
};
871
-
```
872
-
873
-
1. Handle the message and call the callback function:
0 commit comments