Call a function from another class in React-Native (Functional component)

May 26, 2021

![Call a function from another class in React-Native (Functional component) ](/images/uploads/Call a function from another class in React-Native (Functional component) .png “Call a function from another class in React-Native (Functional component) “)

App.js

import React from 'react'
import { View, Text } from 'react-native'
import Go from './Go';
const App = () => {
  return ( 
    <View style={{flex:1,justifyContent: 'center',alignItems:'center'}}>
      <Text onPress={()=>Go.abc()}>Call Go Comoponet function</Text>
    </View>
  ) 
}
//static props
App.abc = ()=>{
  alert('hit from App Comoponet')
};
export default App;  
 

Go.js

import React from 'react'
import { View, Text } from 'react-native'
import App from './App';
const Go = () => {
    return (
        <View style={{flex:1,justifyContent: 'center',alignItems:'center'}}>
             <Text onPress={()=>App.abc()}>Call App Comoponet function</Text>
        </View>
    )
} 
//static props
Go.abc = ()=>{
    alert('hit from Go Comoponet')
};
export default Go;

Written by Manoj Bhardwaj who lives and works in Dharamshala Himachal Pradesh (India). My stackoverflow