I want to pass handleLogin in App.js to home.js however when I do I get the error: [TypeError: this.props.extraData.handleLogin is not a function. (In 'this.props.extraData.handleLogin(data)', 'this.props.extraData.handleLogin' is undefined)]
How do I properly pass a function in stack navigator so I can use it in the props in another component? I think I'm missing something with the this context
App.js:
export default class App extends Component {
constructor() {
super();
this.state = {
loggedInStatus: "NOT_LOGGED_IN",
user: {}
};
console.log("APP PROPS", this)
this.handleLogin = this.handleLogin.bind(this);
this.handleLogout = this.handleLogout.bind(this);
}
handleLogin(data) {
this.setState({
loggedInStatus: "LOGGED_IN",
user: data.user
});
}
render() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" >
{props => <Home {...props} extraData={this.handleLogin}/>}
</Stack.Screen>
<Stack.Screen name= "Login" >
{props => <Login {...props}/>}
</Stack.Screen>
<Stack.Screen name="Registration">
{props => <Registration {...props} extraData={this.handleLogin, this.handleLogout, this.loggedInStatus}/>}
</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
);
}
}
Home.js:
export default class Home extends Component {
constructor(props) {
super(props);
console.log("HOME PROPS", this.props)
this.handleSuccessfulAuth = this.handleSuccessfulAuth.bind(this);
this.handleLogoutClick = this.handleLogoutClick.bind(this);
}
handleSuccessfulAuth(data) {
this.props.extraData.handleLogin(data);
this.props.history.push("/dashboard");
}