I am new to react and have read the docs for synthetic event handlers but still can't figure out how to solve my problem. I have a react app with a router. There is a button for logging in and for logging out. On logout there is an onClick handler like this:
<a onClick={() => { signOut; this.myFunction(foo); }}><Link to="./login">Log Out</Link></a>
I want to add a similar function on login. But on login I can't use onClick because the content should only be rendered if the credentials are valid. There is an asynchronous call to the database and if the credentials are valid, the following code is executed:
if (valid) {
return (
<Redirect to="/home" />
)
}
How can I call myFunction when it redirects to home? Any help would be appreciated.