- Notifications
You must be signed in to change notification settings - Fork21
🪢 Simplest React state manager
License
NotificationsYou must be signed in to change notification settings
nanxiaobei/resso
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Link in bio towidgets,your onlinehome screen. ➫🔗 kee.so
The simplest React state manager.Auto on-demand re-render ⚡️
ReactiveElegantSharedStoreObject
(Support React 18, React Native, SSR, Mini Apps)
English ·简体中文
resso, world’s simplest React state manager →
- Extremely simple 🪩
- Extremely smart 🫙
- Extremely small 🫧
pnpm add resso# oryarn add resso# orbun add resso# ornpm i resso
importressofrom'resso';conststore=resso({count:0,text:'hello',inc(){const{ count}=store;// must destructure at top (if use in method)store.count=count+1;},});functionApp(){const{ count}=store;// must destructure at top (if use in UI)return(<>{count}<buttononClick={()=>(store.count+=1)}>+</button></>);}
* destructure at top is callinguseState (Hooks rules, or may get React error)
Single update
store.count=60;store('count',(c)=>c+1);
Multiple update
store({count:60,text:'world',});store((s)=>({count:s.count+1,text:s.text==='hello' ?'world' :'hello',}));
Non-state shared vars (Refs)
Actually, it's not related to resso, it's just JavaScript. You can do it like this:
// store.jsexportconstrefs={total:0,};// App.jsimportstore,{refs}from'./store';functionApp(){refs.total=100;return<div/>;}
*react<18 batch update
resso.config({batch:ReactDOM.unstable_batchedUpdates});// at app entry
// no text update, no re-renderfunctionText(){const{ text}=store;return<p>{text}</p>;}// only when count updates, re-renderfunctionCount(){const{ count}=store;return<p>{count}</p>;}// no state in UI, no re-renderfunctionControl(){return(<><buttononClick={store.inc}>+</button><buttononClick={()=>(store.count-=1)}>-</button></>);}
About
🪢 Simplest React state manager
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.