Reputation: 9284
Having the following React code:
// foo element
<NavLink onClick={(e) => this.sectionSelected(e)} />
//method invoqued
sectionSelected(e) {
e.preventDefault();
// foo actions
// this.setState( ... )
// trigger the click again
// e.retrigger()
}
How can I retrigger the click that I cancelled using preventDefault
?
Looking for an answer not involving jquery.
Upvotes: 1
Views: 364
Reputation: 266
I don't think there is a way to suspend default event behaviour in the way you want.
You could wrap the NavLink
to handle the click AND follow the default behaviour...
const NavLinkWithOnClick = ({
clickHandler,
to
}) => (
<div onClick={clickHandler}>
<NavLink to={to} />
</div>
)
...
<NavLinkWithOnClick clickHandler={sectionSelected] to="/wherever" />
Upvotes: 1