How to Convert Integer Variable to String in React Native Application

This tutorial is very important for beginners, who just start developing apps in react native. In this tutorial we would going to solve the most common String Conversion Error “TypeError: expected dynamic type string but had type int64”. This error is usually comes when react native developer print Integer value without converting it into Alert message box. So here is the complete step by step tutorial for Convert Integer Variable to String in React Native Android iOS Example using VariableName.toString() method.

The Error should look like below screenshot :

Contents in this project Convert Integer Variable to String in React Native App :

1. Import StyleSheet, View, Button and Alert component in your class.

2. Create a function named as ConvertFunction() in your App class. As you can see in below function we have declare a Var named as ValueHolder and set its value to 10 . Now its a Int64 type value and the Alert dose not support Integer. So we would change the Var value using .toString() method in Alert. This function would convert the Int64 value into pure string.

3. Create a Button in render’s return block and call the ConvertFunction() function on Button onPress event.

4. Create CSS for View component.

5. Complete source code for App.js File :

Screenshot :

Convert Integer Variable

Leave a Reply

Your email address will not be published. Required fields are marked *