0

When I add click event for the button it shows this error in ios simulator如何解决这个错误“RawText必须被包裹在明确的文本组件”的反应,本机组件

renderLastSlide(index) { 
    if (index === this.props.data.length - 1) { 
    return (
     <Container> 
     <Content> 
      <Button rounded light> 
      <Text>Light</Text> 
      onPress={this.props.onComplete} 
      </Button> 
     </Content> 
     </Container> 
    ); 
    } 
} 

什么是与此代码导致该错误的问题?

+0

您的缩进太糟糕了,请编辑它。修复后,你可以自己看到你的错误。 –

回答

0

我们需要在任何元素上指定事件。

上的按钮进行指定onPress

<Button rounded light onPress={this.props.onComplete}> 
    <Text>Light</Text>  
</Button> 
0

你有onPress参数超出按钮的,所以把它放在它里面。

renderLastSlide(index) { 
if (index === this.props.data.length - 1) { 
    return (
    <Container> 
     <Content> 
      <Button rounded light onPress={this.props.onComplete}> 
       <Text>Light</Text> 
      </Button> 
     </Content> 
    </Container> 
); 
} 
+0

非常感谢。当点击按钮事件不起作用时,错误消失。这似乎是反应导航的错误,因为所有需要的脚本都添加在屏幕和app.js文件中。 –

0

海你需要把按钮放在按钮里面。

renderLastSlide(index) { 
    if (index === this.props.data.length - 1) { 
    return (
     <Container> 
     <Content> 
      <Button 
      title= 'hai' 
      onPress={this.props.onComplete} // Add here 
      rounded 
      light 
      /> 
     </Content> 
     </Container> 
    ); 
    } 

如果你想使用文本组件,我认为更喜欢使用TouchableOpacity而不是Button。所以我们可以在标题上添加样式。

相关问题