stellation_stylist/frontend.rs
1use stylist::manager::StyleManager;
2use stylist::yew::ManagerProvider;
3use yew::html::ChildrenProps;
4use yew::prelude::*;
5
6/// A Stylist [`ManagerProvider`] that hydrates styles from SSR automatically.
7/// This provider should be used in the client app instance.
8///
9/// # Panics
10///
11/// This provider requires a [`BackendManagerProvider`](crate::BackendManagerProvider) to be
12/// placed in the server app or hydration will fail.
13///
14/// You can check out this [example](https://github.com/futursolo/stellation/blob/main/examples/fullstack/client/src/app.rs) for how to use this provider.
15#[function_component]
16pub fn FrontendManagerProvider(props: &ChildrenProps) -> Html {
17 let manager = use_memo(
18 |_| StyleManager::new().expect("failed to create style manager."),
19 (),
20 )
21 .as_ref()
22 .to_owned();
23
24 html! {
25 <ManagerProvider {manager}>
26 {props.children.clone()}
27 </ManagerProvider>
28 }
29}