From dd9edca804f74baccc487055c584b786bd3bc478 Mon Sep 17 00:00:00 2001 From: shan-shaji Date: Fri, 10 Apr 2026 10:55:43 +0200 Subject: [PATCH 1/8] docs: tutorial(0.23): update outdated fetching data section Fetching data section of the tutorial page still mentioned using `wasm-bindgen-futures::spawn_local`. Updated the docs and examples to use `yew::platform::spawn_local` and the `use_future` hook instead. --- .../version-0.23/tutorial/index.mdx | 121 ++++++++++++++---- 1 file changed, 93 insertions(+), 28 deletions(-) diff --git a/website/versioned_docs/version-0.23/tutorial/index.mdx b/website/versioned_docs/version-0.23/tutorial/index.mdx index 4b13c2d931d..a86616db445 100644 --- a/website/versioned_docs/version-0.23/tutorial/index.mdx +++ b/website/versioned_docs/version-0.23/tutorial/index.mdx @@ -479,7 +479,6 @@ Let's update the dependencies in `Cargo.toml` file: +yew = { version = "0.23", features = ["csr", "serde"] } +gloo-net = "0.6" +serde = { version = "1.0", features = ["derive"] } -+wasm-bindgen-futures = "0.4" ``` Yew's `serde` feature enables integration with the `serde` crate, the important point for us is that @@ -506,12 +505,70 @@ struct Video { } ``` -Now as the last step, we need to update our `App` component to make the fetch request instead of using hardcoded data +Now we need to update our `App` component to fetch data. The modern yew way to do this is with -```rust {2,6-50,59-60} +[`use_future`](https://docs.rs/yew/0.23.0/yew/suspense/fn.use_future.html) and +[``](https://yew.rs/docs/concepts/suspense). + +Alternatively, you can use [`yew::platform::spawn_local`](https://docs.rs/yew/latest/yew/platform/fn.spawn_local.html) +if hooks are unavailable, such as within struct components or standard functions. + +`use_future` suspends the component until the async operation completes, and `` shows a +fallback UI (e.g. a loading indicator) in the meantime. + +We split the data fetching logic into a child component (`VideosFetcher`) that returns `HtmlResult`, +while the parent `App` wraps it in ``: + +```rust {3-4} use yew::prelude::*; +use serde::Deserialize; +use gloo_net::http::Request; ++use yew::suspense::use_future; +// .. ++#[derive(Properties, PartialEq)] ++struct VideosFetchProps { ++ on_click: Callback