2017-07-18 82 views
0

我希望我的應用程序計算日期。要做到這一點,我輸入3個日期和一個按鈕,它應該打印在一個警報。測試時,我似乎有一個錯誤。我的按鈕:React Native:預期的動態類型「字符串」,但有類型「對象」

<TouchableOpacity onPress={() => {{Alert.alert("Box", <calculator date {this.state.dateInit} />)}}}> 
    <View style={styles.button}> 
     <Text style={styles.buttonText}>Calculer</Text> 
    </View> 
</TouchableOpacity> 

和計算器指

class calculator extends Component { 
    render() { 
    return (
     <Text>Le CQE Initial etait le {String(this.props.date)}</Text> 
    ); 
    } 
} 

我this.props.date.toString()和字符串(this.props.date)嘗試無論是在警報和類我仍然得到一個錯誤

TypeError: expected dynamic type string but had type object

同時的toString()或字符串(...)應該把它譯爲字符串。

Thx求救!

回答

1

你傳遞一個組件在第二個參數alert功能

Alert.alert("Box", <calculator date {this.state.dateInit} /> 

,但所描述的here

+0

是的alert第二個參數應該是字符串,它確實是正確的。我會嘗試使用react-navigation代替。我仍然必須瞭解功能如何在反應原生^^中工作。謝謝 ! –

相關問題