- Notifications
You must be signed in to change notification settings - Fork42
🍸 Auto Optimized State Manager for React Hooks
License
NotificationsYou must be signed in to change notification settings
nanxiaobei/flooks
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Link in bio towidgets,your onlinehome screen. ➫🔗 kee.so
- Gorgeous auto optimized re-render
- Automatic request loading
- Extremely simple API
pnpm add flooks# oryarn add flooks# ornpm i flooks
importcreatefrom'flooks';constuseCounter=create((store)=>({count:0,add(){const{ count}=store();store({count:count+1});},asyncaddAsync(){awaitnewPromise((resolve)=>setTimeout(resolve,1000));const{ add}=store();add();},}));functionCounter(){const{ count, add, addAsync}=useCounter();return(<div><p>{count}</p><buttononClick={add}>+</button><buttononClick={addAsync}>+~{addAsync.loading&&'...'}</button></div>);}
* Automatic request loading - if a function is async,asyncFn.loading is its loading state. IfasyncFn.loading is not used, no extra re-render.
flooks realizes a gorgeous auto optimization, only actually used data will be injected into the component, re-render completely on demand, when React is truly "react".
// zustand, need a selectorconst{ nuts, honey}=useStore((state)=>({nuts:state.nuts,honey:state.honey,}));// flooks, not need a selector// but also only `nuts` or `honey` update trigger re-render, it's automaticconst{ nuts, honey}=useStore();
const{ a}=useStore();// A component, update `a`const{ fn}=useStore();// B component, only functions, no re-render
const{ a}=useStore();// A component, update `a`const{ b}=useStore();// B component, no `a`, no re-render
const{ asyncFn}=useStore();// A component, call `asyncFn`asyncFn();// No `asyncFn.loading`, no extra re-render// With normal loading solutions, even `asyncFn.loading` is not used,// it will re-render at least twice (turn `true` then `false`).
importcreatefrom'flooks';constuseStore=create((store)=>obj);// For `react<=17`, you can use `create.config()` to pass// `ReactDOM.unstable_batchedUpdates` for batch updating in async updates.//// create.config({ batch: ReactDOM.unstable_batchedUpdates }); // at app entry
importcreatefrom'flooks';constuseStore=create((store)=>({fn(){const{ a, b}=store();// get statestore({a:a+b});// update state by data// orstore((state)=>({a:state.a+state.b}));// update state by function},}));
About
🍸 Auto Optimized State Manager for React Hooks
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.