mocheng / react-and-redux

《深入浅出React和Redux》代码

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chapter-03代码有错误:this.context.store.unsubscribe(this.onChange)

yuanhjty opened this issue · comments

在 redux_basic, redux_smart_dumb, redux_with_context 实现 componentWillUnmount 时都用了

componentWillUnmount() {
    this.context.store.unsubscribe(this.onChange);
}

Redux store 没有 unsubscribe 这个 api,但是由于 这个几个例子中 componentWillUnmount 永远不会被调用,所以构建和运行时并不会报错。

https://redux.js.org/basics/store
補充一下,
// Note that subscribe() returns a function for unregistering the listener
const unsubscribe = store.subscribe(() =>
console.log(store.getState())
)
執行 subscribe 後回傳的函數來解除.

2年了 作者也不来回复