Top Related Projects
Rust / Wasm framework for creating reliable and efficient web applications
Build fast web applications with Rust.
Fullstack app framework for web, desktop, mobile, and more.
A Rust framework for creating web apps
Facilitating high-level interactions between Wasm modules and JavaScript
Quick Overview
Sycamore is a reactive web framework for Rust, designed to make it easy to build fast and efficient web applications. It provides a declarative syntax for building user interfaces, with a focus on performance and developer experience.
Pros
- Reactive Approach: Sycamore uses a reactive programming model, which makes it easier to manage the state of your application and update the UI in response to changes.
- Performance: Sycamore is designed to be fast and efficient, with a focus on minimizing the amount of DOM manipulation required.
- Rust-based: Sycamore is written in Rust, which provides a strong type system, memory safety, and high performance.
- Flexible and Extensible: Sycamore is designed to be flexible and extensible, with a modular architecture that makes it easy to add new features and functionality.
Cons
- Smaller Community: Compared to some other web frameworks, Sycamore has a smaller community and ecosystem, which may make it harder to find resources and support.
- Steeper Learning Curve: Rust can have a steeper learning curve than some other programming languages, which may make it more challenging for developers to get started with Sycamore.
- Limited Browser Support: Sycamore currently only supports modern browsers, which may limit its usefulness for certain types of web applications.
- Experimental: Sycamore is still a relatively new project, and some of its features and APIs may be subject to change as the framework matures.
Code Examples
Here are a few examples of how to use Sycamore:
- Creating a Simple Component:
use sycamore::prelude::*;
#[component]
fn HelloWorld<'a>(cx: Scope<'a>) -> impl IntoView {
let name = Signal::new("World".to_string());
view! { cx,
div {
"Hello, " { name.get() } "!"
}
}
}
- Handling Events:
use sycamore::prelude::*;
#[component]
fn Counter<'a>(cx: Scope<'a>) -> impl IntoView {
let count = Signal::new(0);
let increment = |_| count.set(*count.get() + 1);
let decrement = |_| count.set(*count.get() - 1);
view! { cx,
div {
button(on:click=increment) { "+" }
" " { count.get() } " "
button(on:click=decrement) { "-" }
}
}
}
- Using Lifecycle Hooks:
use sycamore::prelude::*;
#[component]
fn LifecycleExample<'a>(cx: Scope<'a>) -> impl IntoView {
let count = Signal::new(0);
on_mount(cx, move |_| {
count.set(1);
});
on_update(cx, move |prev_props, props| {
if prev_props.count != props.count {
count.set(*props.count + 1);
}
});
view! { cx,
div { "Count: " { count.get() } }
}
}
Getting Started
To get started with Sycamore, you'll need to have Rust installed on your system. You can then create a new Sycamore project using Cargo:
cargo new my-sycamore-app
cd my-sycamore-app
Next, add the Sycamore dependency to your Cargo.toml
file:
[dependencies]
sycamore = "0.7.0"
You can then start building your Sycamore application by creating components and using the view!
macro to define your UI. Here's a simple example:
use sycamore::prelude::*;
#[component]
fn App<'a>(cx: Scope<'a>) -> impl IntoView {
view!
Competitor Comparisons
Rust / Wasm framework for creating reliable and efficient web applications
Pros of Yew
- More mature and established project with a larger community
- Extensive documentation and examples available
- Supports server-side rendering out of the box
Cons of Yew
- Steeper learning curve due to more complex API
- Larger bundle sizes compared to Sycamore
- Slower compilation times, especially for larger projects
Code Comparison
Yew:
use yew::prelude::*;
#[function_component(App)]
fn app() -> Html {
html! { <h1>{"Hello, World!"}</h1> }
}
Sycamore:
use sycamore::prelude::*;
#[component]
fn App<G: Html>(cx: Scope) -> View<G> {
view! { cx, h1 { "Hello, World!" } }
}
Both frameworks use a component-based approach, but Sycamore's syntax is more concise and closer to HTML. Yew uses a macro-based html!
syntax, while Sycamore uses a view!
macro with a more intuitive structure. Sycamore's components are generic over the rendering backend, allowing for greater flexibility in deployment targets.
Build fast web applications with Rust.
Pros of Leptos
- Fine-grained reactivity system, allowing for more efficient updates
- Built-in server-side rendering (SSR) support
- Integrated routing system
Cons of Leptos
- Steeper learning curve due to more complex reactivity model
- Less mature ecosystem compared to Sycamore
- Potentially higher initial bundle size
Code Comparison
Sycamore:
#[component]
fn App<G: Html>(cx: Scope) -> View<G> {
view! { cx,
div {
"Hello, World!"
}
}
}
Leptos:
#[component]
fn App() -> impl IntoView {
view! {
<div>"Hello, World!"</div>
}
}
Both Sycamore and Leptos are Rust-based frontend frameworks for building web applications. They share similarities in their component-based approach and use of a virtual DOM for efficient rendering.
Sycamore offers a simpler API and may be easier for beginners to grasp. It has a more established ecosystem and community support. However, Leptos provides more advanced features like fine-grained reactivity and built-in SSR, which can lead to better performance in complex applications.
The choice between the two frameworks depends on the specific needs of your project and your familiarity with reactive programming concepts.
Fullstack app framework for web, desktop, mobile, and more.
Pros of Dioxus
- More comprehensive ecosystem with additional tools like Dioxus CLI and Dioxus Desktop
- Supports multiple rendering backends (Web, Desktop, Mobile, TUI)
- Larger community and more active development
Cons of Dioxus
- Steeper learning curve due to more complex architecture
- Larger bundle size compared to Sycamore
- May be overkill for simple web applications
Code Comparison
Dioxus:
#[component]
fn App(cx: Scope) -> Element {
let count = use_state(cx, || 0);
cx.render(rsx! {
button { onclick: move |_| count += 1, "Count: {count}" }
})
}
Sycamore:
#[component]
fn App<G: Html>(cx: Scope) -> View<G> {
let count = create_signal(cx, 0);
view! { cx,
button(on:click=move |_| count.set(*count.get() + 1)) { "Count: " (count.get()) }
}
}
Both frameworks use a component-based approach, but Dioxus uses a more React-like syntax with the rsx!
macro, while Sycamore uses a view!
macro. Dioxus leverages its Scope
type for managing component state, whereas Sycamore uses signals for reactive state management.
A Rust framework for creating web apps
Pros of Seed
- More mature and established project with a larger community
- Extensive documentation and examples available
- Built-in routing system for single-page applications
Cons of Seed
- Larger bundle size due to more features and abstractions
- Steeper learning curve for beginners
- Less flexible for custom optimizations
Code Comparison
Seed:
#[update]
fn increment(by: u32) {
Model.counter += by;
}
Sycamore:
#[component]
fn Counter() -> View<G> {
let state = create_signal(0);
view! {
button(on:click=move |_| state.set(state.get() + 1)) {
(state.get())
}
}
}
Both Seed and Sycamore are Rust frameworks for building web applications. Seed offers a more comprehensive solution with built-in routing and a larger ecosystem, making it suitable for complex projects. Sycamore, being newer, focuses on simplicity and performance, leveraging fine-grained reactivity.
Seed uses a more traditional Model-Update-View architecture, while Sycamore employs a component-based approach with reactive primitives. This difference is reflected in their code structures, with Seed using global state updates and Sycamore utilizing local component state.
Ultimately, the choice between Seed and Sycamore depends on project requirements, team expertise, and performance needs.
Facilitating high-level interactions between Wasm modules and JavaScript
Pros of wasm-bindgen
- More mature and widely adopted project with extensive documentation
- Provides low-level control over JavaScript interop
- Supports a broader range of use cases beyond web development
Cons of wasm-bindgen
- Steeper learning curve for beginners
- Requires more boilerplate code for simple tasks
- Less opinionated, which can lead to inconsistent coding patterns
Code Comparison
wasm-bindgen:
#[wasm_bindgen]
pub fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}
Sycamore:
#[component]
fn Greeting<G: Html>(cx: Scope, name: &str) -> View<G> {
view! { cx,
p { "Hello, " (name) "!" }
}
}
While wasm-bindgen focuses on low-level JavaScript interop, Sycamore provides a higher-level abstraction for building web applications. wasm-bindgen is more flexible but requires more manual work, whereas Sycamore offers a more opinionated and streamlined approach to web development with Rust and WebAssembly.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Sycamore
Sycamore is a reactive library for creating web apps in Rust and WebAssembly.
#[component]
fn Hello() -> View {
view! {
p { "Hello World!" }
}
}
- Lightning Speed: Sycamore harnesses the full power of Rust via WebAssembly, giving you full control over performance.
- Ergonomic and Intuitive: Write code that feels natural. Everything is built on reactive primitives without a cumbersome virtual DOM.
- No JavaScript: Had enough of JavaScript? So have we. Create apps using Sycamore without touching a single line of JS.
Documentation
Sycamore is extensively documented:
- Getting Started: How to write your first Sycamore app.
- Reactivity: Find out how to use Sycamore's powerful reactive primitives.
- API Documentation: rustdocs for the
sycamore
crate.
Still have questions? Don't hesitate to stop by our friendly Discord server.
Examples
Sycamore has many examples for your reference in the
examples/
directory. Be sure to
check them out!
Viewing on sycamore-rs.netlify.app
All the examples are hosted under sycamore-rs.netlify.app/examples/<example_name>
with
<example_name>
being the name of the example you want to view. For instance, the todomvc
example
is hosted on
sycamore-rs.netlify.app/examples/todomvc
.
Building Locally
All the examples can also be built locally using Trunk. For instance, the
following command builds and serves the todomvc
example:
cd examples/todomvc
trunk serve
Now open up localhost:8080
in your browser to see "Hello World!".
Perseus
Perseus is a fullstack framework built with Sycamore. Think NextJS or SvelteKit but with no JavaScript. Everything from backend to frontend is built with pure Rust!
Alternatives?
Don't think Sycamore is for you? Thankfully, there are plenty of alternatives!
- SolidJS: A declarative, efficient and flexible JavaScript
library for building user interfaces
Solid is a JavaScript library which greatly inspired Sycamore. Many concepts such as fine-grained reactivity and components as factory functions were borrowed from Solid. If you don't mind working with JavaScript (or TypeScript), go check it out! - Leptos: Build fast web applications with Rust.
Leptos is another Rust library based on the fine-grained reactivity paradigm. Leptos shares many similarities with Sycamore and, as of now, has a larger community. - Dioxus: Fullstack app framework for web, desktop, mobile,
and more.
Dioxus uses a VDOM instead of fine-grained reactivity for updating the DOM, although it uses fine-grained reactivity for state management. This allows Dioxus to target a wide variety of platforms including native and mobile.
Contributing
- Report issues on our issue tracker.
- We love Pull Requests! For more information, check out the section on contributing in the docs.
Sycamore would not have been possible without the wonderful contributions from the community. Thank you!
Special thanks to @nate-sys for designing the Sycamore logo!
Top Related Projects
Rust / Wasm framework for creating reliable and efficient web applications
Build fast web applications with Rust.
Fullstack app framework for web, desktop, mobile, and more.
A Rust framework for creating web apps
Facilitating high-level interactions between Wasm modules and JavaScript
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot