Utility components and functions for Dioxus fullstack apps.
Renders an RFC 3339 datetime string as a <time> element in the browser's
local timezone.
- During SSR: displays UTC (e.g.
2025-06-15 14:30). - On the client (post-hydration):
use_effect+js_sys::Dateconverts to the browser's local timezone. No JavaScript eval or global scripts.
Props:
| Prop | Type | Default | Description |
|---|---|---|---|
datetime |
String |
— | RFC 3339 datetime string (required) |
class |
String |
"" |
Optional CSS class on <time> |
use dioxus::prelude::*;
use dx_utils::LocalTime;
#[component]
fn UsageRow(hour_bucket: String) -> Element {
rsx! {
td { LocalTime { datetime: hour_bucket } }
}
}Redirect to an external URL. Works correctly during both SSR and client-side navigation.
- During SSR: sets HTTP 302 status and a
Locationheader viaFullstackContext, producing a real HTTP redirect before any HTML reaches the browser. - On the client (post-hydration): uses
navigator().replace()withNavigationTarget::Externalfor a client-side navigation.
use dioxus::prelude::*;
use dx_utils::redirect_external;
#[component]
fn AuthGuard() -> Element {
let auth = use_server_future(|| check_auth())?;
let binding = auth.read();
let status = binding.as_ref().and_then(|r| r.as_ref().ok());
if let Some(s) = status {
if !s.authenticated {
redirect_external(&s.login_url);
return rsx! {};
}
}
rsx! { Outlet::<Route> {} }
}Add to your Cargo.toml:
[dependencies]
dx-utils = "0.2"
[features]
server = ["dx-utils/server"]| Feature | Description |
|---|---|
server |
Enables SSR redirect via FullstackContext and http crate |
- Dioxus 0.7+
- Rust 1.75+
MIT