rax
🐰 Rax is a progressive framework for building universal application. https://rax.js.org
Top Related Projects
The library for web and native user interfaces.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Deliver web apps with confidence 🚀
Cybernetically enhanced web apps
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
Quick Overview
Rax is a universal React-compatible framework developed by Alibaba. It allows developers to build cross-platform applications using a single codebase, supporting web, mobile, and mini-program platforms. Rax aims to provide a lightweight and performant solution for building user interfaces.
Pros
- Cross-platform development: Build once, run on multiple platforms
- React-compatible: Familiar syntax and concepts for React developers
- Lightweight and performant: Optimized for mobile and web environments
- Rich ecosystem: Includes various components and tools for rapid development
Cons
- Smaller community compared to React Native or other cross-platform frameworks
- Limited documentation and resources in English
- Steeper learning curve for developers not familiar with Alibaba's ecosystem
- May lack some advanced features found in more mature frameworks
Code Examples
- Creating a simple component:
import { createElement, render } from 'rax';
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
render(<Greeting name="Rax" />);
- Using hooks for state management:
import { createElement, useState } from 'rax';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}
- Fetching data with useEffect:
import { createElement, useState, useEffect } from 'rax';
function UserList() {
const [users, setUsers] = useState([]);
useEffect(() => {
fetch('https://api.example.com/users')
.then(response => response.json())
.then(data => setUsers(data));
}, []);
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
Getting Started
To start using Rax, follow these steps:
- Install the Rax CLI:
npm install -g rax-cli
- Create a new Rax project:
rax init my-rax-app
cd my-rax-app
- Install dependencies and start the development server:
npm install
npm run start
- Open your browser and navigate to
http://localhost:9999
to see your Rax app in action.
For more detailed information and advanced usage, refer to the official Rax documentation.
Competitor Comparisons
The library for web and native user interfaces.
Pros of React
- Larger community and ecosystem, with more resources, libraries, and tools available
- More mature and battle-tested in production environments
- Better performance for complex, large-scale applications
Cons of React
- Steeper learning curve, especially for beginners
- Requires additional libraries for state management in larger applications
- More opinionated approach to component structure and lifecycle
Code Comparison
React:
import React from 'react';
function MyComponent({ name }) {
return <div>Hello, {name}!</div>;
}
Rax:
import { createElement, render } from 'rax';
function MyComponent({ name }) {
return <div>Hello, {name}!</div>;
}
Key Differences
- Rax aims for better cross-platform compatibility, including web, native, and mini-programs
- React focuses primarily on web and native platforms
- Rax has a smaller footprint and faster initial render times for simple applications
- React offers more advanced features and optimizations for complex UIs
Use Cases
- Choose React for large-scale web applications with complex state management
- Consider Rax for lightweight, cross-platform projects, especially those targeting mini-programs
- React is better suited for teams with existing React experience or those requiring extensive third-party integrations
- Rax may be preferable for projects prioritizing small bundle sizes and quick startup times
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 integration with existing web technologies
Cons of Vue
- Steeper learning curve for beginners
- Potentially slower performance for complex applications
- Less focus on cross-platform development
Code Comparison
Vue:
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello Vue!'
}
}
}
</script>
Rax:
import { createElement, render } from 'rax';
function App() {
return <div>Hello Rax!</div>;
}
render(<App />);
Vue uses a template-based approach with separate script and template sections, while Rax follows a more React-like syntax with JSX. Vue's component structure is more verbose but potentially easier to understand for beginners. Rax's approach is more concise and may be more familiar to React developers.
Both frameworks aim to provide efficient rendering and component-based architecture, but Vue has a larger ecosystem and more widespread adoption. Rax, developed by Alibaba, focuses on cross-platform development and performance optimization, particularly for mobile applications.
Deliver web apps with confidence 🚀
Pros of Angular
- More mature and widely adopted framework with a larger community and ecosystem
- Comprehensive documentation and extensive learning resources available
- Built-in dependency injection system for better modularity and testability
Cons of Angular
- Steeper learning curve due to its complexity and TypeScript requirement
- Larger bundle size, which can impact initial load times
- More opinionated structure, potentially limiting flexibility in some cases
Code Comparison
Angular component:
@Component({
selector: 'app-example',
template: '<h1>{{ title }}</h1>'
})
export class ExampleComponent {
title = 'Hello Angular';
}
Rax component:
import { createElement, render } from 'rax';
function Example() {
return <h1>Hello Rax</h1>;
}
render(<Example />);
Summary
Angular is a robust, full-featured framework with a large ecosystem, while Rax is a lightweight, performance-focused library for building cross-platform applications. Angular offers more built-in features and structure, but comes with a steeper learning curve. Rax, being more lightweight, provides flexibility and easier adoption, especially for developers familiar with React-like syntax. The choice between the two depends on project requirements, team expertise, and performance considerations.
Cybernetically enhanced web apps
Pros of Svelte
- Smaller bundle sizes due to compile-time optimization
- Simpler, more intuitive syntax with less boilerplate
- Built-in state management without additional libraries
Cons of Svelte
- Smaller ecosystem and community compared to React-based frameworks
- Less suitable for large-scale applications with complex state management
- Limited tooling and IDE support
Code Comparison
Svelte component:
<script>
let count = 0;
function increment() {
count += 1;
}
</script>
<button on:click={increment}>
Clicks: {count}
</button>
Rax component:
import { createElement, useState } from 'rax';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicks: {count}
</button>
);
}
Both Svelte and Rax aim to provide efficient and performant UI development experiences. Svelte focuses on compile-time optimization and a simpler syntax, while Rax leverages React-like concepts for cross-platform development. Svelte's approach results in smaller bundle sizes and less runtime overhead, but Rax benefits from the extensive React ecosystem and tooling. The choice between the two depends on project requirements, team expertise, and specific use cases.
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Pros of Preact
- Smaller bundle size (3KB gzipped) compared to Rax's larger footprint
- More mature and widely adopted in the developer community
- Closer API compatibility with React, making migration easier
Cons of Preact
- Less focus on cross-platform development compared to Rax
- Fewer built-in optimizations for mobile performance
- Smaller ecosystem of custom components and tools
Code Comparison
Preact:
import { h, render } from 'preact';
const App = () => <h1>Hello, World!</h1>;
render(<App />, document.body);
Rax:
import { createElement, render } from 'rax';
const App = () => <h1>Hello, World!</h1>;
render(<App />, document.body);
Both Preact and Rax aim to provide lightweight alternatives to React, but they have different focuses. Preact prioritizes size and React compatibility, while Rax emphasizes cross-platform development and performance optimizations for mobile devices. The code syntax is very similar, with minor differences in import statements and rendering methods. Developers familiar with React will find both libraries relatively easy to adopt, but Preact's closer alignment with React's API may provide a smoother transition for existing React projects.
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
Pros of Inferno
- Higher performance: Inferno is known for its exceptional speed and efficiency in rendering
- Smaller bundle size: Inferno has a smaller footprint, which can lead to faster load times
- More mature project: Inferno has been around longer and has a larger community
Cons of Inferno
- Less flexibility: Inferno is more opinionated and may offer fewer customization options
- Steeper learning curve: Inferno's unique approach may require more time to master
- Limited ecosystem: Fewer third-party libraries and tools compared to Rax
Code Comparison
Inferno:
import { render } from 'inferno';
function MyComponent({ name }) {
return <div>Hello, {name}!</div>;
}
render(<MyComponent name="World" />, document.getElementById('app'));
Rax:
import { render, createElement } from 'rax';
function MyComponent({ name }) {
return <div>Hello, {name}!</div>;
}
render(<MyComponent name="World" />, document.getElementById('app'));
Both frameworks use a similar syntax for creating components and rendering them to the DOM. The main difference lies in the imported libraries and the underlying implementation details.
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
Rax is a progressive framework for building universal applications.
ð Write Once, Run Anywhere: write one codebase, run with Web
, Weex
, Node.js
, Alibaba MiniApp
, and WeChat MiniProgram
. Rax can be used with additional containers that implement it's driver specification.
â± Fast: better performance and a tiny size(ð¦~6KB) when compared to React using the same API.
ð¤ Easy: quick start with zero configuration, all features like Progressive Web App (PWA)
, Server-Side Rendering (SSR)
, and Function as a service (FaaS)
can be used out of the box.
Quick Start ð¥¢ð
Start from command line
Create a new Rax project using create-rax
:
$ npm init rax <YourProjectName>
npm init <initializer>
is available in npm 6+
Start local server to launch project:
$ cd <YourProjectName>
$ npm install
$ npm run start
Start from VS Code
You need to install the AppWorks Pack and invoke the Create Application
command from the VS Code command palette (Ctrl + Shift + P
or Cmd + Shift + P
on Mac):
Developer Tools ð
You can inspect and modify the state of your Rax components at runtime using the
Rax Developer Tools browser extension,
however the extension will not work in production
mode.
- Install the Chrome Rax Developer Tools extension
- Reload and go to the 'Rax' tab in the browser's development tools
VS Code Extension
You can use AppWorks Pack to get better development experience.
Awesome Things ð
You can find some awesome things in awesome-rax.
Contributing ð§¼
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing.
Code Contributors
This project exists thanks to all the people who contribute.
Community support
For general help using Rax, please refer to the official site. For additional help, you can use one of these channels to ask a question:
- GitHub (Bug reports, contributions)
- Twitter (Get the news fast)
- Medium (Get blogs and articles)
- ç¥ä¹ä¸æ (Get blogs and articles in Simplified Chinese)
Top Related Projects
The library for web and native user interfaces.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Deliver web apps with confidence 🚀
Cybernetically enhanced web apps
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
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