Proyectos
Ver en GitHub
nanxiaobei/resso
Acerca de
🪢 El gestor de estado más sencillo para React
Desarrollo web y de aplicacionesWhat you can do
- Extremely simple
- Extremely smart
- Extremely small
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
OriginalLink in bio to widgets, your online home screen. ➫ 🔗 kee.so
🪢 resso
The simplest React state manager. Auto-handle on-demand re-render.
Reactive Elegant Shared Store Object
English · 简体中文
[!NOTE] Breaking changes since v0.29.0:
- (To better fit AI & React Compiler) In React components, always use
const { count } = store.useStore()to get state. Direct accessstore.countorconst { count } = storeis now for pure data reads.- Only supports
react >= 18.
Introduction
resso, world’s simplest React state manager →
Features
- Extremely simple
- Extremely smart
- Extremely small
Demo
Install
bun add resso
#
pnpm add resso
#
yarn add resso
#
npm i resso
Usage
import resso from 'resso';
const store = resso({
count: 0,
text: 'hello',
inc() {
store.count += 1;
},
});
function App() {
const { count, inc } = store.useStore();
return (
<>
{count}
<button onClick={inc}>+</button>
<button onClick={() => (store.count -= 1)}>-</button>
</>
);
}
API
Get
// Get state, in component
const { count } = store.useStore();
// Read state, in method
function doSomething() {
const total = store.count * 2;
const filtered = store.list.filter((item) => item.name !== '');
// ...
}
Set (triggers re-render)
// Single
store.count = 60;
store('count', (c) => c + 1);
// Multiple
store({
count: 60,
text: 'world',
});
store((s) => ({
count: s.count + 1,
text: s.text === 'hello' ? 'world' : 'hello',
}));
Shared Refs
Actually, it's not related to resso, it's just JavaScript. You can do it like this:
// store.js
export const refs = {
total: 0,
};
// App.js
import store, { refs } from './store';
function App() {
refs.total = 100;
return <div />;
}
Re-render on demand
// No `text` update, no re-render
function Text() {
const { text } = store.useStore();
return <p>{text}</p>;
}
// Only `count` update triggers re-render
function Count() {
const { count } = store.useStore();
return <p>{count}</p>;
}
// No state in UI, no re-render
function Control() {
return (
<>
<button onClick={store.inc}>+</button>
<button onClick={() => (store.count -= 1)}>-</button>
</>
);
}
License
Explorar proyectos relacionados
Cargando…