How to Call Another Class Function From Default Class in React Native

React Native supports multiple classes format like we used in other programming languages like Java, C++, PHP etc. So in this tutorial we would going to create a react native application with multiple(2) classes and Call Another Class Function From Default Class on button onPress event.

Contents in this project Call Another Class Function From Default Class :

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

2. Create another class named as Second and extends component to it. This class would be our another class. Now we would create 2 function in this class one function without argument and second function with argument. We would also print the Sample text in these functions using Alert message.

3. Create constructor in your project’s main class. For example my default class name is MyProject, so i am creating the constructor inside MyProject class. Inside this constructor we would create object of Second class named as Obj. Object is used to call the function from another class.

4. Create 2 Functions in your default class named as CallFunction_1 and CallFunction_2. We are calling the another class function using our main class functions using their object.

5. Create Root View with 2 Button component inside render’s return block.

6. Create Style for Root View.

7. Complete source code for App.js File :

Screenshots in Android device :

Call Another Class Function

Screenshot in iOS device :