Skip to content

Commit d335494

Browse files
committed
feat(link): allow additional control over onclick
1 parent 00a9933 commit d335494

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Link.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ const Link = ({ children, url, ...props }) => (
1010
<a href={ url } { ...props }>{ children }</a>
1111
);
1212

13-
const mapDispatchToProps = ( dispatch, { url }) => ({
13+
const mapDispatchToProps = ( dispatch, { onClick = null, shouldScrollToTop = true, url }) => ({
1414
onClick: e => {
1515
e.preventDefault();
16+
17+
if ( onClick ) {
18+
onClick( e, dispatch );
19+
}
20+
1621
window.history.pushState({}, '', url );
22+
1723
dispatch( updateUrl( url ));
18-
scrollToTop();
24+
25+
if ( shouldScrollToTop ) {
26+
scrollToTop();
27+
}
1928
},
2029
});
2130

0 commit comments

Comments
 (0)