ReactDOM.render(
<Provider store={Store}>
<HashRouter>
<App />
</HashRouter>
</Provider>
, document.getElementById('root'));在組件中連接store 以前用的是connect ;發(fā)現(xiàn)在組件中用static contextTypes = {
store: PropTypes.object.isRequired,
};
然后
const { store } = this.context也可以取到 store ;想問哪種方式比較好?
2 回答

慕村9548890
TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個贊
前一種,因?yàn)閷?shí)際上connect的實(shí)現(xiàn)方式就是個高階組件,用的就是this.context的方式
添加回答
舉報
0/150
提交
取消