Search code examples
javascriptreactjsauthenticationreact-props

Why my props action doesn't work in an "if" statement in "onClick", but it works outside the "if" statement?


This code works:

<button onClick={props.action}>
     Sign in
</button>

This code doesn't work:

<button class="btn btn-outline-primary" type="button" onClick={() => logIn(username, password).then((res) => res.data===0 ? props.action : console.log(res.data) )}>
        Sign in
</button>

I'm new to reactjs Does any body know why it doesn't work in the second way?


Solution

  • Just a tip; Make a function and then call the funciton onClick instead. The code gets simpler to read!