ctron / yew-consent

Managing consent with Yew

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yew-consent

crates.io docs.rs

Managing user consent with Yew

Usage

Add it to your project:

cargo add yew-consent

Then, add it your application component:

#[function_component(Application)]
fn application() -> Html {
    let ask = use_callback((), |context, ()| html!(<AskConsent {context} />));

    html!(
        <Consent<()> {ask}>
            <State/>
        </Consent<()>>
    )
}

And then, you can check consent later:

#[function_component(State)]
fn state() -> Html {
    let consent = use_consent::<()>();

    html!(
        <>
            <dl>
                <dt>{"Consent state"}</dt>
                <dd>{ format!("{consent:#?}")}</dd>
            </dl>
        </>
    )
}

Also see the example here: example.

You can run the example using:

cd example
trunk serve

About

Managing consent with Yew

License:Apache License 2.0


Languages

Language:Rust 95.5%Language:HTML 4.5%