无论何时
animationType
或
animationComplete
更改后,Splash组件将重新呈现。我不明白为什么当没有道具传递到渲染器时它会重新渲染。
export class Splash extends React.Component {
static propTypes = {
animationType: allowNullPropType(PropTypes.string),
animationComplete: PropTypes.bool,
changeAnimation: PropTypes.func
};
componentDidMount() {
const {changeAnimation} = this.props;
// ...
}
componentDidUpdate() {
const {animationType, animationComplete} = this.props;
const shouldChangeScreen = (animationType === 'out' && animationComplete);
if (shouldChangeScreen) {
const {navigation} = this.props;
// ...
}
}
render() {
return (
<Fade id='splash' styles={styles.container}>
<Logo height='125' width='125'/>
</Fade>
);
}
}
const mapStateToProps = (state) => {
return {
animationType: state.fade.getIn(['splash', 'type']),
animationComplete: state.fade.getIn(['splash', 'complete'])
}
};
const mapDispatchToProps = (dispatch) => {
return {
changeAnimation: (id, type) => dispatch(changeAnimation(id, type))
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Splash);
我尝试用一个简单的视图组件替换Fade(它也连接到Redux store和dispatches actions)和Logo组件,但问题仍然存在。我也试过使用重新选择。
shouldComponentUpdate() {
return false;
}
但这似乎不是一个很好的解决方案。