Skip to content

Commit 00a9933

Browse files
committed
feat(link): scroll to top after link click
1 parent b1fbe0f commit 00a9933

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Link.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import React from 'react';
22
import { connect } from 'react-redux';
33
import { updateUrl } from './actions';
44

5+
const scrollToTop = () => {
6+
document.documentElement.scrollTop = document.body.scrollTop = 0;
7+
};
8+
59
const Link = ({ children, url, ...props }) => (
610
<a href={ url } { ...props }>{ children }</a>
711
);
@@ -11,6 +15,7 @@ const mapDispatchToProps = ( dispatch, { url }) => ({
1115
e.preventDefault();
1216
window.history.pushState({}, '', url );
1317
dispatch( updateUrl( url ));
18+
scrollToTop();
1419
},
1520
});
1621

0 commit comments

Comments
 (0)