Reactjs redux mapDispatchToProps渲染
当用户单击浏览器后退/前进按钮时,我使用redux undo来操纵活动/非活动按钮状态。My function changeButtonImage()根据当前的redux状态更改活动/非活动菜单按钮图像。我被卡住了,因为mapStateToProps在重新渲染后会更改为新值。但我需要从“浏览器后退按钮处理程序”调用changeButtonImage()。我找到了一个称为store geState()的变通方法,但这是一种反模式的方法。请给我解释一下如何用正确的方式欺骗它Reactjs redux mapDispatchToProps渲染,reactjs,redux,render,mapdispatchtoprops,Reactjs,Redux,Render,Mapdispatchtoprops,当用户单击浏览器后退/前进按钮时,我使用redux undo来操纵活动/非活动按钮状态。My function changeButtonImage()根据当前的redux状态更改活动/非活动菜单按钮图像。我被卡住了,因为mapStateToProps在重新渲染后会更改为新值。但我需要从“浏览器后退按钮处理程序”调用changeButtonImage()。我找到了一个称为store geState()的变通方法,但这是一种反模式的方法。请给我解释一下如何用正确的方式欺骗它 ->
-> console.log('goBack');
console.log(
'before',
isClickItem // mapStateToProps property
// store.getState().itemReducer.present.isClickItem //-> anti-pattern
);
onUndo();
console.log(
'after',
isClickItem // --> nothing changes before re-render
// store.getState().itemReducer.present.isClickItem //-> change but anti-pattern
);
changeButtonImage(); // --> use before undo state