react-and-redux
react-and-redux copied to clipboard
chapter-03代码有错误:this.context.store.unsubscribe(this.onChange)
在 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年了 作者也不来回复