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。所以我們可以在標題上添加樣式。

相關問題