useStore
Minimalist state management tools only for React.js
Features
- Progressive adoption
- Minimalist api
- Extremely reusable
import React from 'react';
import Store, { useStore } from 'back-store';
const Root = () => {
return (
<Store value={{ page1: { count: 1 }, page2: { a: { b: 'hello' } } }}>
<App />
</Store>
);
};
const App = () => {
const [store, setStore] = useStore('page1');
const { count } = store;
const plusOne = () => setStore({ count: count + 1 });
const plusTen = () => setStore(store => ({ count: count + 10 }));
const minusOne = () => setStore('count', count - 1);
return (
<div>
<div>{count}</div>
<button onClick={plusOne}>+</button>
<button onClick={plusOne}>+10</button>
<button onClick={minusOne}>-</button>
</div>
);
};
export default Root;
CHANGELOG
v1.1.0
添加函数式调用