I have a <Button /> component that I created in React that abstracts some styles in my application. I use it in two different contexts: one to submit the login form, and the other to go to the registration page (and, possibly, in other contexts in the future).
I am trying to figure out how to pass event handlers from the parent component to <Button /> . I want to call the onSubmit handler for the login form, but the onClick handler for the navigation button. Is it possible?
I tried calling the component as follows:
<Button text={callToAction} style={styles.callToActionButton} onClick={() => FlowRouter.go("Auth")}/> <Button text="Go!" style={styles.registerButton} onSubmit={() => this.register(this.state.user, this.state.password)}/>
I also tried to remove the function with the arrow, which simply forces the function to execute when the component loads:
// executes event handlers on page load <Button text={callToAction} style={styles.callToActionButton} onClick={FlowRouter.go("Auth")}/> <Button text="Go!" style={styles.registerButton} onSubmit={this.register(this.state.user, this.state.password)}/>
source share