Zustand 和 Jotai 是最小化状态库,用远少于 Redux 的样板代码实现全局状态,并内置选择性订阅以避免不必要的重新渲染。它们采用不同的心智模型:Zustand 是单一存储;Jotai 是原子式的。
Zustand — 简洁的、基于 hook 的存储
jsx
{ create } ;
useStore = ( ({
: ,
: ( ({ : s. + })),
: ({ : }),
}));
() {
count = ( s.);
increment = ( s.);
;
}
