Top Related Projects
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
The library for web and native user interfaces.
Deliver web apps with confidence 🚀
web development for the rest of us
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
A rugged, minimal framework for composing JavaScript behavior in your markup.
Quick Overview
Riot.js is a lightweight, component-based JavaScript library for building user interfaces. It emphasizes simplicity and performance, allowing developers to create reusable UI components with a minimal and intuitive API. Riot.js aims to provide a more straightforward alternative to larger frameworks like React or Vue.
Pros
- Small footprint and fast performance
- Simple and intuitive API for creating components
- Supports both in-browser and server-side rendering
- Easy integration with existing projects
Cons
- Smaller ecosystem compared to more popular frameworks
- Limited advanced features compared to larger alternatives
- Less frequent updates and community contributions
- Steeper learning curve for developers used to more opinionated frameworks
Code Examples
- Creating a simple component:
const MyComponent = {
template: `
<div>
<h1>{ props.title }</h1>
<p>{ state.message }</p>
<button onclick={ handleClick }>Click me</button>
</div>
`,
state: {
message: 'Hello, Riot.js!'
},
handleClick() {
this.update({ message: 'Button clicked!' })
}
}
riot.register('my-component', MyComponent)
- Mounting a component:
riot.mount('my-component', { title: 'Welcome' })
- Using lifecycle hooks:
const LifecycleComponent = {
template: '<div>{ state.count }</div>',
state: { count: 0 },
onBeforeMount() {
console.log('Component will mount')
},
onMounted() {
console.log('Component mounted')
this.timer = setInterval(() => {
this.update({ count: this.state.count + 1 })
}, 1000)
},
onUnmounted() {
clearInterval(this.timer)
console.log('Component unmounted')
}
}
riot.register('lifecycle-component', LifecycleComponent)
Getting Started
To start using Riot.js in your project:
- Install Riot.js via npm:
npm install riot
- Create a component file (e.g.,
my-component.js
):
export default {
template: '<p>Hello, { props.name }!</p>'
}
- Register and mount the component in your main JavaScript file:
import { register, mount } from 'riot'
import MyComponent from './my-component.js'
register('my-component', MyComponent)
mount('my-component', { name: 'Riot.js' })
- Include the component in your HTML:
<my-component></my-component>
Competitor Comparisons
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Pros of Vue
- Larger ecosystem and community support
- More comprehensive documentation and learning resources
- Better performance for complex applications
Cons of Vue
- Steeper learning curve for beginners
- More opinionated structure, which may limit flexibility
- Larger file size compared to Riot
Code Comparison
Vue component:
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, Vue!'
}
}
}
</script>
Riot component:
<hello>
<div>{ message }</div>
<script>
export default {
message: 'Hello, Riot!'
}
</script>
</hello>
Summary
Vue offers a more robust ecosystem and better performance for complex applications, but comes with a steeper learning curve. Riot provides a simpler, more lightweight approach with a flatter learning curve, but may lack some advanced features and community support compared to Vue. The choice between the two depends on project requirements, team expertise, and desired application complexity.
The library for web and native user interfaces.
Pros of React
- Larger ecosystem and community support
- More extensive documentation and learning resources
- Better performance for complex, large-scale applications
Cons of React
- Steeper learning curve, especially for beginners
- Requires additional libraries for full functionality (e.g., routing, state management)
- More verbose syntax compared to Riot's concise approach
Code Comparison
React component:
import React from 'react';
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
export default Greeting;
Riot component:
<greeting>
<h1>Hello, { props.name }!</h1>
<script>
export default {
// Component logic here
}
</script>
</greeting>
React focuses on a JavaScript-centric approach, while Riot uses a more HTML-like syntax with embedded JavaScript. React's component structure is more modular, but Riot's syntax is more compact and may be easier for developers with HTML backgrounds to grasp quickly.
Deliver web apps with confidence 🚀
Pros of Angular
- Comprehensive framework with built-in tools for routing, forms, and HTTP requests
- Large ecosystem with extensive documentation and community support
- Powerful CLI for scaffolding and managing projects
Cons of Angular
- Steeper learning curve due to its complexity and TypeScript requirement
- Larger bundle size, potentially impacting initial load times
- More opinionated, which may limit flexibility in some cases
Code Comparison
Angular component:
@Component({
selector: 'app-hello',
template: '<h1>Hello, {{name}}!</h1>'
})
export class HelloComponent {
name: string = 'World';
}
Riot component:
<hello>
<h1>Hello, { props.name }!</h1>
<script>
export default {
onBeforeMount(props) {
this.name = props.name || 'World'
}
}
</script>
</hello>
Key Differences
- Angular uses TypeScript and decorators, while Riot uses plain JavaScript
- Angular separates template and logic, Riot combines them in a single file
- Angular has a more complex setup, Riot aims for simplicity
- Angular offers more built-in features, Riot focuses on being lightweight
Both frameworks have their strengths, with Angular being more suitable for large-scale applications and Riot excelling in smaller, focused projects where simplicity is key.
web development for the rest of us
Pros of Svelte
- Compiles to vanilla JavaScript, resulting in smaller bundle sizes and better performance
- Offers a more intuitive and less boilerplate-heavy syntax
- Provides built-in state management and reactivity without external libraries
Cons of Svelte
- Smaller ecosystem and community compared to more established frameworks
- Limited server-side rendering options out of the box
- Steeper learning curve for developers accustomed to traditional frameworks
Code Comparison
Svelte component:
<script>
let count = 0;
function increment() {
count += 1;
}
</script>
<button on:click={increment}>
Clicks: {count}
</button>
Riot component:
<counter>
<button onclick={ increment }>
Clicks: { state.count }
</button>
<script>
export default {
state: {
count: 0
},
increment() {
this.update({
count: this.state.count + 1
})
}
}
</script>
</counter>
Both Svelte and Riot aim to simplify web development, but Svelte's compile-time approach and more concise syntax give it an edge in terms of performance and developer experience. However, Riot's smaller footprint and easier integration with existing projects may be advantageous in certain scenarios.
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Pros of Preact
- Smaller bundle size and faster performance due to its lightweight nature
- Closer compatibility with React ecosystem and APIs
- More active development and larger community support
Cons of Preact
- Less feature-rich compared to Riot's built-in state management and routing
- Steeper learning curve for developers new to React-like frameworks
- May require additional libraries for features that come out-of-the-box with Riot
Code Comparison
Preact component:
import { h, Component } from 'preact';
class Greeting extends Component {
render({ name }) {
return <h1>Hello, {name}!</h1>;
}
}
Riot component:
<greeting>
<h1>Hello, { props.name }!</h1>
<script>
export default {
onBeforeMount(props, state) {
// Component logic here
}
}
</script>
</greeting>
The code comparison shows that Preact follows a more React-like syntax with JSX, while Riot uses a custom tag-based syntax that combines HTML, JavaScript, and CSS in a single file. Preact's approach may be more familiar to React developers, while Riot's syntax aims for simplicity and readability.
A rugged, minimal framework for composing JavaScript behavior in your markup.
Pros of Alpine
- Lighter weight and smaller bundle size
- Easier learning curve for developers familiar with HTML attributes
- Seamless integration with existing HTML without requiring a build step
Cons of Alpine
- Less powerful for complex applications compared to Riot's component-based approach
- Limited ecosystem and fewer third-party extensions
- Lacks built-in state management for larger applications
Code Comparison
Alpine:
<div x-data="{ open: false }">
<button @click="open = !open">Toggle</button>
<span x-show="open">Content</span>
</div>
Riot:
<toggle>
<button onclick={ toggle }>Toggle</button>
<span if={ open }>Content</span>
<script>
export default {
state: { open: false },
toggle() { this.update({ open: !this.state.open }) }
}
</script>
</toggle>
Alpine uses HTML attributes for reactivity, while Riot employs a more structured component approach with separate logic. Alpine's syntax is more inline with HTML, making it easier for designers to work with, but Riot's component structure may be more familiar to developers coming from other JavaScript frameworks.
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
Simple and elegant component-based UI library
Custom components ⢠Concise syntax ⢠Simple API ⢠Tiny Size
Riot brings custom components to all modern browsers. It is designed to offer you everything you wished the native web components API provided.
Tag definition
<timer>
<p>Seconds Elapsed: { state.time }</p>
<script>
export default {
tick() {
this.update({ time: ++this.state.time })
},
onBeforeMount(props) {
// create the component initial state
this.state = {
time: props.start,
}
this.timer = setInterval(this.tick, 1000)
},
onUnmounted() {
clearInterval(this.timer)
},
}
</script>
</timer>
Mounting
// mount the timer with its initial props
riot.mount('timer', { start: 0 })
Nesting
Custom components let you build complex views with HTML.
<timetable>
<timer start="0"></timer>
<timer start="10"></timer>
<timer start="20"></timer>
</timetable>
HTML syntax is the de facto language on the web and it's designed for building user interfaces. The syntax is explicit, nesting is inherent to the language and attributes offer a clean way to provide options for custom tags.
Performant and predictable
- Absolutely the smallest possible amount of DOM updates and reflows.
- Fast expressions bindings instead of virtual DOM memory performance issues and drawbacks.
- One way data flow: updates and unmounts are propagated downwards from parent to children.
- No "magic" or "smart" reactive properties or hooks
- Expressions are pre-compiled and cached for high performance.
- Lifecycle methods for more control.
Close to standards
- No proprietary event system.
- Future proof thanks to the javascript module syntax.
- The rendered DOM can be freely manipulated with other tools.
- No extra HTML root elements,
data-
attributes or fancy custom attributes. - No new syntax to learn.
- Plays well with any frontend framework.
Use your dearest language and tools
- Create components with CoffeeScript, Jade, LiveScript, Typescript, ES6 or any pre-processor you want.
- Build with @riotjs/cli, webpack, Rollup, parcel, Browserify.
- Test however you like; you can load your riot tags directly in node
Powerful and modular ecosystem
The Riot.js ecosystem is completely modular, it's designed to let you pick only the stuff you really need:
- @riotjs/cli - CLI to locally compile your tags to javascript
- @riotjs/ssr - Super simple server side rendering
- @riotjs/hydrate - Hydration strategy for your SPA
- @riotjs/route - Isomorphic router
- @riotjs/lazy - Lazy components loader
- @riotjs/hot-reload - Live reload plugin
- @riotjs/compiler - Advanced tags compiler
- @riotjs/parser - HTML parser
- @riotjs/dom-bindings - Expressions based template engine
- @riotjs/custom-elements - native custom elements implementation
CDN hosting
How to contribute
If you are reading this it's already a good sign and I am thankful for it! I try my best working as much as I can on riot but your help is always appreciated.
If you want to contribute to riot helping the project maintenance please check first the list of open issues to understand whether there is a task where you could help.
Riot is mainly developed on UNIX systems so you will be able to run all the commands necessary to build and test the library using our Makefile. If you are on a Microsoft machine it could be harder to set up your development environment properly.
Following the steps below you should be able to properly submit your patch to the project
1) Clone the repo and browse to the riot folder
git clone git@github.com:riot/riot.git && cd riot
2) Set up your git branch
git checkout -b feature/my-awesome-patch
3) Install the npm dependencies
npm i
4) Build and test riot using the Makefile
# To build and test riot
$ make riot
# To build without testing
$ make raw
5) Pull request only against the main
branch making sure you have read our pull request template
6) Be patient
Credits
Riot is actively maintained with :heart: by:
![]() Gianluca Guarini |
Many thanks to all smart people from all over the world who helped improving it.
Official Website
Backers
Support us with a monthly donation and help us continue our activities. Become a backer
Sponsors
Become a sponsor to get your logo on our README. Become a sponsor
Thanks
Special thanks to Browserstack for their support
|
Top Related Projects
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
The library for web and native user interfaces.
Deliver web apps with confidence 🚀
web development for the rest of us
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
A rugged, minimal framework for composing JavaScript behavior in your markup.
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