React@16.x(55)Redux@4.x(4)- store

目录

1,介绍

之前的文章中,已经逐步介绍了使用的情况,这里再做下补充,常用的3个属性:

  • dispatch 方法,用于分发 action
  • getState 方法,用于得到最新的 state
  • subscribe 方法,用于在 state 发生变化时执行。

subscribe 使用举例:

js 复制代码
import { createStore } from "redux";
import reducer from "./reducer";

const store = createStore(reducer);
// 每次 store.dispatch() 执行时,下面的回调函数就会执行。
const unListen = store.subscribe(() => {
    console.log(store.getState());
});

// 终止监听。
unListen()

其他相关:

1,核心概念

2,action 介绍

3,reducer 介绍


以上。

相关推荐
LuckyDog阿祥18 分钟前
卸载Microsoft Edge:EdgeRemover完整操作指南
前端·edge
zhangxingchao22 分钟前
AI应用开发九:从 Hermes Agent 学长期记忆
前端·人工智能·后端
我是大卫25 分钟前
【图】React源码解析-第四部分:事件与跨层传递
react.js·源码
xiaofeichaichai36 分钟前
Vite原理与Webpack对比
前端·webpack·node.js
_杨瀚博39 分钟前
小程序拍证件并局部裁剪
前端
张元清1 小时前
React useReducedMotion Hook:尊重 prefers-reduced-motion(2026)
javascript·react.js
William_Xu2 小时前
React 新旧生命周期对比
前端