Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 再次按下时如何将文字值更改回默认值_Reactjs_React Native Android - Fatal编程技术网

Reactjs 再次按下时如何将文字值更改回默认值

Reactjs 再次按下时如何将文字值更改回默认值,reactjs,react-native-android,Reactjs,React Native Android,我正在使用React Native创建一个应用程序,当我单击GO文本时,它将更改为字母X。但是,当我再次单击后退X时,我还需要显示GO文本。 下面是代码 this.state = { textValue:"You're Offile", cancel:'X', textGo:"GO", } onChange = () => { this.setState({


我正在使用React Native创建一个应用程序,当我单击
GO
文本时,它将更改为字母
X
。但是,当我再次单击后退
X
时,我还需要显示
GO
文本。

下面是代码

    this.state = {
    textValue:"You're Offile",
    cancel:'X',
    textGo:"GO",
    }
      onChange = () => {
        this.setState({
          textValue: 'Finding Rides',
          textGo:"X"
        });
      };
    
    
     <TouchableOpacity onPress={() => this.onChange()}>
                  <Text 
                   //onPress={() => this.onChange()}
                  style={{
                    fontSize:30,
                    fontWeight:"bold",
                    color:"white"
                  }}>{this.state.textGo}</Text>
                </TouchableOpacity>

this.state={
textValue:“你是Offile”,
取消:'X',
textGo:“GO”,
}
onChange=()=>{
这是我的国家({
textValue:“查找游乐设施”,
textGo:“X”
});
};
this.onChange()}>
this.onChange()}
风格={{
尺寸:30,
fontWeight:“粗体”,
颜色:“白色”
}}>{this.state.textGo}

您可以在onChnage方法中检查条件并根据它更新您的状态

onChange = () => {

   if(this.state.textGo === "X")
   {
       this.setState({
         textValue: 'You're Offile',
         textGo:"GO"
       });
   }
   else
   {
       this.setState({
          textValue: 'Finding Rides',
          textGo:"X"
        });
   }
    
  };



请详细解释您的问题。this.state={textValue:“您不在办公室”,cancel:'X',textGo:“去”,status:false,}onChange=()=>{if(!this.state.status)this.setState({textValue:'Finding Rides',textGo:'X“state:true});}else{if(!this.state.state)this.setState)({textValue:'Finding Rides',textGo:'X“state:false});};