المشاريع
عرض على GitHub
nanxiaobei/resso
حول
🪢 أبسط مدير لحالة React
تطوير الويب والتطبيقاتما يمكنك فعله
- Extremely simple
- Extremely smart
- Extremely small
النمو المقاس للنجوم
- خلال 24 ساعة
- ٠
- خلال 7 أيام
- ٠
- خلال 15 يومًا
- ٠
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلLink 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
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…