How to perform some actions on root class on specific event on nested element?
This is my code. Is it possible to call onLogout function from App class from Account class? If I don't use StactNavigator and just export Account class, it's possible to use onLogout function from index.js
index.js
var Account = require('./account');
export default class App extends Component {
onLogout= () => {
}
render() {
return (
<TabBarIOS selectedTab={this.state.selectedTab}>
<TabBarIOS.Item}}>
<Welcome />
</TabBarIOS.Item>
<TabBarIOS.Item}}>
{this.state.isAuth ? <Account onLogout= {this.onLogout} /> : <AuthView/> }
</TabBarIOS.Item>
</TabBarIOS>
);
}
}
account.js
import { StackNavigator } from 'react-navigation';
class Account extends Component {
constructor(props) {
super(props);
this.state = {
lastName: ''
};
}
handleLogout = () => {
console.log("Logout");
// LOGGING IN
// Next line throws an exception, 'onLogout is not a function'
// this.props.onLogout();
}
render() {
return (
<Button
title = "Logout"
onPress = {this.handleLogout}
/>
);
}
}
const AccountView = StackNavigator({
Home: { screen: Account }
//Detail : {screnn: DetailView}
});
module.exports = AccountView;