use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};
use leptos::prelude::*;
#[derive(Clone)]
pub struct UidContext(Arc<AtomicU64>);
#[component]
pub fn UidRoot(children: Children) -> impl IntoView {
provide_context(UidContext(Arc::new(AtomicU64::new(0))));
children()
}
pub fn generate(prefix: &str) -> String {
let ctr = if let Some(ctx) = use_context::<UidContext>() {
ctx.0.fetch_add(1, Ordering::SeqCst)
} else {
static FALLBACK: AtomicU64 = AtomicU64::new(0);
FALLBACK.fetch_add(1, Ordering::SeqCst)
};
format!("{}-{:08x}", prefix, ctr)
}