當我單擊某個InspectorOption組件時,我的redux記錄器顯示分派了一個動作,並且狀態如預期更新。組件在動作分派和狀態更新時無法重新渲染
My InspectorSelect和children InspectorOption組件使用react-redux的連接到mapStateToProps,這些組件依賴於來自狀態的道具。
但即使狀態正在更新並且組件依賴於狀態,組件也不會在狀態更新時重新呈現。
爲什麼我的組件在狀態改變時不能重新渲染,我該如何糾正?
@connect((state) => {
return {
options: state.inspector.options
}
})
export default class InspectorSelect extends Component {
render() {
return (
<div>
{
this.props.options.map(option => {
return <InspectorOption
option={ option }
key={ option.id }
/>
})
}
</div>
)
}
}
https://github.com/caseysiebel/dashboard/blob/master/src/components/InspectorSelect.js#L17
99.9%的時間,這是由於在還原器(或代碼中的其他地方)中Redux狀態的意外突變。請參閱http://redux.js.org/docs/faq/ReactRedux.html#react-not-rerendering。 – markerikson
正如以前的評論所述,這可能是由國家變異引起的。如果你會發布你的減速器有人能夠發現錯誤 –