This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on docs.rs.

yew/functional/hooks/use_transitive_state/
mod.rs

1#[cfg(feature = "hydration")]
2mod feat_hydration;
3#[cfg(all(feature = "ssr", feature = "hydration"))]
4mod feat_hydration_ssr;
5#[cfg(not(any(feature = "hydration", feature = "ssr")))]
6mod feat_none;
7#[cfg(feature = "ssr")]
8mod feat_ssr;
9
10#[cfg(all(feature = "hydration", not(feature = "ssr")))]
11pub use feat_hydration::*;
12#[cfg(all(feature = "ssr", feature = "hydration"))]
13pub use feat_hydration_ssr::*;
14#[cfg(not(any(feature = "hydration", feature = "ssr")))]
15pub use feat_none::*;
16#[cfg(all(feature = "ssr", not(feature = "hydration")))]
17pub use feat_ssr::*;
18/// Use a state created as an artifact of the server-side rendering.
19///
20/// This value is created after the server-side rendering artifact is created.
21///
22/// It accepts a closure as the first argument and a dependency type as the second argument.
23/// It returns `SuspensionResult<Option<Rc<T>>>`.
24///
25/// It will always return `Ok(None)` during server-side rendering.
26///
27/// During hydration, it will only return `Ok(Some(Rc<T>))` if the component is hydrated from a
28/// server-side rendering artifact and its dependency value matches.
29///
30/// `let state = use_transitive_state!(deps, |deps| -> ReturnType { ... });`
31///
32/// It has the following function signature:
33///
34/// ```
35/// # use serde::de::DeserializeOwned;
36/// # use serde::Serialize;
37/// # use std::rc::Rc;
38/// use yew::prelude::*;
39/// use yew::suspense::SuspensionResult;
40///
41/// #[hook]
42/// pub fn use_transitive_state<T, D, F>(deps: D, f: F) -> SuspensionResult<Option<Rc<T>>>
43/// where
44///     D: Serialize + DeserializeOwned + PartialEq + 'static,
45///     T: Serialize + DeserializeOwned + 'static,
46///     F: 'static + FnOnce(Rc<D>) -> T,
47/// # { todo!() }
48/// ```
49///
50/// If the bundle is compiled without server-side rendering, the closure will be stripped
51/// automatically.
52///
53/// # Note
54///
55/// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This
56/// type is used during client side rendering to deserialize the state prepared on the server
57/// side.
58pub use use_transitive_state_macro as use_transitive_state;
59// With SSR.
60#[doc(hidden)]
61#[cfg(feature = "ssr")]
62pub use yew_macro::use_transitive_state_with_closure as use_transitive_state_macro;
63// Without SSR.
64#[doc(hidden)]
65#[cfg(not(feature = "ssr"))]
66pub use yew_macro::use_transitive_state_without_closure as use_transitive_state_macro;