Function use_artifacts

Source
pub fn use_artifacts<'hook, T>() -> impl 'hook + Hook<Output = Vec<Rc<T>>>
where T: PartialEq + 'static + 'hook,
Expand description

A hook to read all artifacts of the current artifact type.

An artifact is a global side effect (e.g.: document title) that will be collected in the rendering order.

§Note

If you are trying to manipulate elements in the <head /> element (e.g.: document title), it is recommended to use the Helmet API instead.

§Example

#[derive(Debug, PartialEq)]
pub struct Title {
    inner: String,
}

#[function_component(Inner)]
fn inner() -> Html {
    html! {<Artifact<Title> value={Rc::new(Title { inner: "My Title 2".into() })} />}
}

#[function_component(Outer)]
fn outer() -> Html {
    html! {
        <>
            <Artifact<Title> value={Rc::new(Title { inner: "My Title 1".into() })} />
            <Inner />
        </>
    }
}

// [Title { inner: "My Title 1" }, Title { inner: "My Title 2" }]
let title_artifacts = use_artifacts::<Title>();

§Note

When used in function components and hooks, this hook is equivalent to:

pub fn use_artifacts<T>() -> Vec<Rc<T>>
where
    T: PartialEq + 'static,
{
    /* implementation omitted */
}