美文网首页
redux 笔记

redux 笔记

作者: Lzzzzzq | 来源:发表于2017-04-14 17:02 被阅读0次

    Store

    • Store 就是保存数据的地方。
    • 可以看作是一个容器。
    • 整个应用只能有一个 Store。

    Redux 提供 createStore 这个函数,用来生成 Store。

    import { createStore } from 'redux';
    const store = createStore(fn);
    

    上面代码中,createStore 函数接受另一个函数作为参数,返回新生成的 Store 对象。

    State

    • Store对象包含所有数据。
    • 如果想得到某个时点的数据,就要对 Store 生成快照。这种时点的数据集合,就叫做 State。
    • 当前时刻的 State,可以通过store.getState()拿到。
    import { createStore } from 'redux';
    const store = createStore(fn);
    
    const state = store.getState();
    

    Redux 规定, 一个 State 对应一个 View。只要 State 相同,View 就相同。

    相关文章

      网友评论

          本文标题:redux 笔记

          本文链接:https://www.haomeiwen.com/subject/ceuzittx.html