I'm trying to pass a function to a child component so that I can return some data to save in the root component's state.
<Route exact path="/signin" component={Signin}
render={(props)=>(<Signin {...props} updateAppState={this.updateAppState}></Signin>)}></Route>}
Above it shows how I pass the function to the component as a prop. Below is the function itself:
updateAppState = () => {
console.log("Reached")
this.setState({loggedin:true});
}
Here is how I am attempting to use the function in the child component:
signIn = () => {
Axios.post(`http://localhost:3001/mongooose/checkUser`,this.state)
.then(data=>data.data=='Session started'?(alert(data.data),console.log(this.props),this.props.updateAppState()):alert(data.data))
.catch(err=>console.log(err))
}