1

I want my app to calculate dates. To do so, i input 3 dates and with a button, it should print them in an alert. When testing, i seem to have a bug. My button is :

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

and calculator refers to

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

I tried with this.props.date.toString() and String(this.props.date) both in the alert and the class and i still get an error

TypeError: expected dynamic type string but had type object

while toString() or String(...) should have translated it as string.

Thx for the help !

1 Answer 1

1

You are passing a component in second argument of alert function

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

but the second argument of alert should be string as described here

Sign up to request clarification or add additional context in comments.

1 Comment

yes, it is indeed right. I'll try and use react-navigation instead. I still have to understand how function work in react native ^^. Thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.