React native 对行为不了解

React native 对行为不了解,react-native,React Native,目前,我正在学习react native,但仍然不知道为什么会发生这种情况。 我有a组分和B组分 在组件A中,当处理成功时,我将通过Issucceed:对于失败案例,为true和false。 但我不知道为什么当有成功案例时,它会导航到B屏幕,并在显示success文本1秒之前始终显示Fail文本 component A: login() { dataService.getService().then((response) => { navigateService.n

目前,我正在学习react native,但仍然不知道为什么会发生这种情况。 我有a组分和B组分

在组件A中,当处理成功时,我将通过Issucceed:对于失败案例,为true和false。 但我不知道为什么当有成功案例时,它会导航到B屏幕,并在显示
success
文本1秒之前始终显示
Fail
文本

component A: 

login() {
   dataService.getService().then((response) => {
       navigateService.navigate('B', {isSucceeded: true})
    }).catch(error => {
     navigateService.navigate('B', {isSucceeded: false})
    });
}
在构成部分B中:

componentDidMount() {
this.state.isSucceeded = navigation.getParam('isSucceeded')
}

render() {
 this.state.isSucceeded ? <View> <Text>Success</Text></View> : 
                          <View> <Text>Fail</Text></View>
}
componentDidMount(){
this.state.issucceedd=navigation.getParam('issucceedd')
}
render(){
this.state.issueded?成功:
失败
}
有成功案例和失败案例失败时,如何显示成功文本


谢谢。

您应该在
构造函数中执行此操作

constructor(props) {
  super(props);

  this.state = {
    isSucceeded: props.navigation.getParam('isSucceeded'),
  };
}
如果您坚持在
componentDidMount
中执行此操作,则必须使用
setState()


与setState和state=params有什么区别吗?(如果这是一个愚蠢的问题,很抱歉)
componentDidMount() {
  const isSucceeded = this.props.navigation.getParam('isSucceeded');

  this.setState({ isSucceeded });
}