如果组件未连接到redux存储,状态更改不会触发新渲染,因此不会更新组件。
按照目前的方式,只有当
render
已调用方法get。。。
一种可能的解决方案是
AppBar
组件转换为另一个连接到redux状态的组件,因此只要在存储中更新所需的状态部分,它就会更新
const mapStateToProps = (state, ownProps) {
const { isAuthenticated } = state.authentication // Get whatever you need from the reducer that handles authentication state
return { isAuthenticated }
}
class MyAppBar extends Component {
...
render(){
return(<AppBar iconElementRight={this.props.isAuthenticated ? <Menu /> : null} {rest of your props})
}
}
export default connect(mapStateToProps)(MyAppBar)
这样,组件将跟踪与身份验证缩减器相关的存储上的任何更改,并触发呈现方法(在需要时执行检查)