unistore 特性Usage 介绍
unistore 是一个微型(650B)的集中式状态容器。
特性
Usage
import { Provider, createStore, connect } from 'unistore' let store = createStore({ count: 0 }) // If actions is a function, it gets passed the store: let actions = store => ({ // Actions can just return a state update: increment(state) { return { count: state.count+1 } }, // The above example as an Arrow Function: increment2: ({ count }) => ({ count: count+1 }), // Async actions can be pure async/promise functions: async getStuff(state) { let res = await fetch('/foo.json') return { stuff: await res.json() } }, // ... or just actions that call store.setState() later: incrementAsync(state) { setTimeout( () => { store.setState({ count: state.count+1 }) }, 100) } }) const App = connect('count', actions)( ({ count, increment }) => ( <div> <p>Count: {count}</p> <button onClick={increment}>Increment</button> </div> ) ) export default () => ( <Provider store={store}> <App /> </Provider> )
unistore 特性Usage 官网
https://github.com/developit/unistore
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。