diff --git a/website/docs/concepts/suspense.mdx b/website/docs/concepts/suspense.mdx index 6c697d82f00..efd8d1e566c 100644 --- a/website/docs/concepts/suspense.mdx +++ b/website/docs/concepts/suspense.mdx @@ -78,6 +78,23 @@ fn use_user() -> SuspensionResult { } ``` +#### Note on implementing suspending hooks + +[`Suspension::new`](https://docs.rs/yew/latest/yew/suspense/struct.Suspension.html#method.new) returns 2 values: the suspension context itself, and a suspension handle. +The latter is the one responsible for signaling when to re-render the suspended components, it provides 2 interchangable ways to do so: + +1. Calling its [`resume`](https://docs.rs/yew/latest/yew/suspense/struct.SuspensionHandle.html#method.resume) method. +2. Dropping the handle. + +:::danger + +The suspension handle must be stored until it's time to update components, i.e. with newly received data; +otherwise, the suspended components will enter an infinite re-render loop, thus hampering performance. +In the example above, the suspension handle is preserved by being moved into a closure and passed into `on_load_user_complete`. +When the hypothetical user will be loaded, the closure will be called, thus calling `handle.resume()` and re-rendering the components associated with the suspension context. + +::: + # Complete Example ```rust