react-and-redux icon indicating copy to clipboard operation
react-and-redux copied to clipboard

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

Open yuanhjty opened this issue 7 years ago • 2 comments

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

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

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

yuanhjty avatar Jan 29 '18 13:01 yuanhjty

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 後回傳的函數來解除.

Nihilatux avatar Jul 05 '18 10:07 Nihilatux

2年了 作者也不来回复

SoftwareEngineerPalace avatar Jan 28 '20 14:01 SoftwareEngineerPalace