Top Related Projects
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
A rugged, minimal framework for composing JavaScript behavior in your markup.
web development for the rest of us
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Simple and elegant component-based UI library
1kB-ish JavaScript framework for building hypertext applications
Quick Overview
Reef is a lightweight JavaScript library for creating reactive, state-based components and UI. It provides a simple and efficient way to build dynamic web applications without the complexity of larger frameworks.
Pros
- Lightweight and fast, with a small footprint (2kb minified and gzipped)
- Simple API that's easy to learn and use
- No build process required, can be used directly in the browser
- Framework-agnostic, can be integrated with other libraries or vanilla JavaScript
Cons
- Limited ecosystem compared to larger frameworks
- May lack some advanced features found in more comprehensive libraries
- Documentation could be more extensive
- Smaller community support compared to popular alternatives
Code Examples
Creating a simple component:
import reef from 'reef';
// Create a component
const app = reef('#app', {
data: {
greeting: 'Hello, world!'
},
template: function (props) {
return `<h1>${props.greeting}</h1>`;
}
});
// Render the component
app.render();
Updating component data:
// Update the data
app.data.greeting = 'Hello, Reef!';
// Reef automatically re-renders the component
Using reactive data with a form:
const form = reef('#form', {
data: {
name: ''
},
template: function (props) {
return `
<input type="text" value="${props.name}">
<p>Hello, ${props.name || 'stranger'}!</p>
`;
}
});
document.addEventListener('input', function (event) {
form.data.name = event.target.value;
});
Getting Started
- Include Reef in your project:
<script src="https://cdn.jsdelivr.net/npm/reefjs/dist/reef.min.js"></script>
- Create a component:
const app = reef('#app', {
data: {
count: 0
},
template: function (props) {
return `
<p>Count: ${props.count}</p>
<button onclick="app.data.count++">Increment</button>
`;
}
});
app.render();
This creates a simple counter component that updates when the button is clicked.
Competitor Comparisons
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Pros of Preact
- Smaller bundle size (3KB gzipped) compared to Reef's larger footprint
- Virtual DOM for efficient updates and better performance
- Compatibility with React ecosystem and components
Cons of Preact
- Steeper learning curve for developers new to React-like frameworks
- Less suitable for simple projects where Reef's minimalism shines
- Requires build tools and transpilation for optimal use
Code Comparison
Reef:
reef.component('#app', {
data: { count: 0 },
template: function (props) {
return `<button>Clicked ${props.count} times</button>`;
}
});
Preact:
import { h, render, Component } from 'preact';
class App extends Component {
state = { count: 0 };
render(props, state) {
return <button onClick={() => this.setState({ count: state.count + 1 })}>
Clicked {state.count} times
</button>;
}
}
render(<App />, document.body);
Summary
Preact offers a more robust solution for complex applications with its virtual DOM and React compatibility, while Reef provides a simpler, lightweight alternative for basic reactive interfaces. The choice between them depends on project requirements, developer expertise, and performance needs.
A rugged, minimal framework for composing JavaScript behavior in your markup.
Pros of Alpine
- More feature-rich with built-in directives for common tasks
- Larger community and ecosystem with more resources and plugins
- Seamless integration with existing HTML, requiring minimal changes
Cons of Alpine
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more concepts and syntax to master
- Less flexibility for custom rendering solutions
Code Comparison
Alpine:
<div x-data="{ open: false }">
<button @click="open = !open">Toggle</button>
<span x-show="open">Content</span>
</div>
Reef:
<div id="app">
<button data-click="toggle">Toggle</button>
<span data-if="open">Content</span>
</div>
const app = new Reef('#app', {
data: { open: false },
template: function (props) {
// Return HTML string
}
});
app.addListener('click', 'toggle', function (event) {
app.data.open = !app.data.open;
});
Alpine offers a more concise, declarative approach with inline directives, while Reef separates concerns with a JavaScript-driven template and event handling. Alpine's syntax is more intuitive for simple interactions, but Reef provides more control over rendering and state management for complex applications.
web development for the rest of us
Pros of Svelte
- More comprehensive framework with built-in state management and routing
- Compiler-based approach results in smaller bundle sizes and better performance
- Larger community and ecosystem with more resources and third-party libraries
Cons of Svelte
- Steeper learning curve due to its unique syntax and concepts
- Less flexibility for integrating with existing projects or other libraries
- Requires a build step, which can complicate the development process
Code Comparison
Svelte component:
<script>
let count = 0;
const increment = () => count += 1;
</script>
<button on:click={increment}>
Clicks: {count}
</button>
Reef component:
import reef from 'reef';
function Counter() {
return `<button data-count="0">Clicks: 0</button>`;
}
const app = reef('#app', Counter);
document.addEventListener('click', function (event) {
if (event.target.matches('[data-count]')) {
let count = parseInt(event.target.getAttribute('data-count'), 10);
event.target.setAttribute('data-count', count + 1);
event.target.textContent = `Clicks: ${count + 1}`;
app.render();
}
});
Both Svelte and Reef aim to simplify web development, but they take different approaches. Svelte offers a more feature-rich framework with its own syntax and compilation step, while Reef provides a lightweight solution that works with vanilla JavaScript and doesn't require a build process.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Pros of Solid
- More comprehensive framework with built-in state management and reactivity system
- Larger community and ecosystem, with more resources and third-party libraries
- Better performance for complex applications due to fine-grained reactivity
Cons of Solid
- Steeper learning curve, especially for developers new to reactive programming
- Larger bundle size, which may impact initial load times for smaller applications
- More opinionated structure, potentially limiting flexibility for certain use cases
Code Comparison
Solid example:
import { createSignal } from "solid-js";
function Counter() {
const [count, setCount] = createSignal(0);
return <button onClick={() => setCount(count() + 1)}>{count()}</button>;
}
Reef example:
import reef from 'reefjs';
function Counter() {
return reef.component({
data: { count: 0 },
template: (props) => `
<button onclick="count++">Count: ${props.count}</button>
`
});
}
Both Solid and Reef aim to provide reactive UI solutions, but Solid offers a more comprehensive framework with additional features and performance optimizations. Reef, on the other hand, focuses on simplicity and a smaller footprint, making it easier to integrate into existing projects or learn for beginners. The choice between the two depends on project requirements, team expertise, and performance needs.
Simple and elegant component-based UI library
Pros of Riot
- More feature-rich with built-in state management and routing capabilities
- Larger community and ecosystem, with more plugins and extensions available
- Better performance for complex applications with many components
Cons of Riot
- Steeper learning curve due to its custom syntax and more extensive API
- Larger bundle size, which may impact initial load times for smaller applications
- Less flexibility in terms of integration with other libraries or frameworks
Code Comparison
Reef:
Reef.component('#app', {
data: { count: 0 },
template: function (props) {
return `<button>Clicks: ${props.count}</button>`;
}
});
Riot:
<my-counter>
<button onclick={ increment }>Clicks: { count }</button>
<script>
export default {
state: { count: 0 },
increment() { this.update({ count: this.state.count + 1 }) }
}
</script>
</my-counter>
Both libraries aim to simplify component-based development, but Riot uses a more opinionated approach with custom tags and built-in state management, while Reef focuses on simplicity and minimal abstraction. Reef may be easier for beginners or smaller projects, while Riot offers more features for complex applications at the cost of a steeper learning curve.
1kB-ish JavaScript framework for building hypertext applications
Pros of Hyperapp
- More comprehensive framework with built-in state management
- Smaller bundle size (1.5KB vs 2.8KB for Reef)
- Virtual DOM implementation for efficient updates
Cons of Hyperapp
- Steeper learning curve due to more complex architecture
- Less flexibility for integration with other libraries or frameworks
- Requires more boilerplate code for simple applications
Code Comparison
Hyperapp:
import { h, app } from "hyperapp"
const view = state => h("div", {}, [
h("h1", {}, state.count),
h("button", { onclick: state => ({ count: state.count + 1 }) }, "Add")
])
app({
init: { count: 0 },
view,
node: document.getElementById("app")
})
Reef:
import reef from 'reefjs'
const app = new reef('#app', {
data: { count: 0 },
template: function (props) {
return `
<h1>${props.count}</h1>
<button onclick="app.data.count++">Add</button>
`
}
})
Both libraries aim to simplify web application development, but Hyperapp offers a more structured approach with built-in state management, while Reef provides a simpler, more flexible solution for smaller projects or integration with existing codebases.
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
Reef
A tiny utility library for building reactive state-based UI.
Reef is a simpler alternative to React, Vue, and other UI libraries. No build steps. No fancy syntax. Just vanilla JS and a few small utility functions.
This code is free to use under the MIT license.
Top Related Projects
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
A rugged, minimal framework for composing JavaScript behavior in your markup.
web development for the rest of us
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Simple and elegant component-based UI library
1kB-ish JavaScript framework for building hypertext applications
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