leptos

Leptos

Specific best practices and architectural patterns when working with Leptos.

Details

Language / Topic
rustRust
Category
framework

Rules

balanced
- Use reactive signals (`create_signal`, `create_memo`) for state; derive computed values with memos instead of duplicating state.
- Use `<Suspense>` and `<Transition>` to handle async data loading in components with proper loading/fallback UI.
- Use `create_signal()` for local reactive state and `create_memo()` for derived values — avoid duplicating state.
- Wrap async data fetches in `create_resource()` and display results inside `<Suspense fallback=...>` components.
- Use `<Transition>` instead of `<Suspense>` when you want to keep showing previous content while new data loads.
- Use server functions (`#[server]`) for backend logic — they run on the server and are callable from client components.
- Use `leptos_router` for client-side routing; define routes with `<Route path="/" view=HomePage />`.