When to call function vs function() in react onClick? [duplicate]

foo() is calling the function referenced by foo. foo itself is just a reference to a function, it doesn’t call the function.

So, you need to use parenthesis if you want to call the function right here and now.
You have to omit the parentheses if you want to pass the function to other code so it can call the function. That would be the case with event handlers. this.props.OnNavigation should be called when the click event happens (which is some time in the future), not when the component is rendered.

Leave a Comment