Orbit is a lightweight React store that eliminates boilerplate with built-in conventions and utilities. Focus on building your app, not on setting up your store.
Get started in 2 steps:
Define a schema and create your store!
// Create the Store - TodoStore
import { z } from 'zod'
import { createModelStore } from '@orbit';
const schema = z.object({
id: z.number().optional(),
name: z.string().min(2).default('Test'),
isDone: z.boolean().default(false)
});
export default createModelStore({ name: 'Todo', schema });
Use your store right away, no need to define reducers, queries, or mutations!
import React from 'react';
import { useAllTodos, useNewTodo } from '@/stores/TodoStore';
function TodoList() {
const todos = useAllTodos();
const newTodo = useNewTodo();
return (
<div>
<form onSubmit={() => newTodo.save()}>
<input
type="text"
value={newTodo.name}
onChange={(e) => newTodo.name = e.target.value;}
placeholder="Add a new task"
/>
<button type="submit">Add</button>
</form>
<ul>
{todos.map(todo => (
<li key={todo.id}>
<span
style={{ textDecoration: todo.isDone ? 'line-through' : 'none' }}
onClick={() => todo.update({isDone: !todo.isDone})}
>
{todo.name}
</span>
<button onClick={() => todo.destory()}>Delete</button>
</li>
))}
</ul>
</div>
);
}
export default TodoList;