File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed
reactjsfoundations.com/src Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change
1
+ import React , { useEffect , Fragment } from 'react' ;
2
+ import { withRouter } from 'react-router-dom' ;
3
+
4
+ function ScrollToTop ( { history, children } ) {
5
+ useEffect ( ( ) => {
6
+ const unlisten = history . listen ( ( ) => {
7
+ window . scrollTo ( 0 , 0 ) ;
8
+ } ) ;
9
+ return ( ) => {
10
+ unlisten ( ) ;
11
+ } ;
12
+ } , [ ] ) ;
13
+
14
+ return < Fragment > { children } </ Fragment > ;
15
+ }
16
+
17
+ export default withRouter ( ScrollToTop ) ;
Original file line number Diff line number Diff line change 1
- import React from "react" ;
2
- import ReactDOM from "react-dom" ;
3
- import { BrowserRouter as Router } from "react-router-dom" ;
4
- import App from "./App" ;
1
+ import React from 'react' ;
2
+ import ReactDOM from 'react-dom' ;
3
+ import { BrowserRouter as Router } from 'react-router-dom' ;
4
+ import App from './App' ;
5
+ import ScrollToTop from './ScrollToTop' ;
6
+
5
7
ReactDOM . render (
6
- < Router >
7
- < App />
8
- </ Router > ,
9
- document . getElementById ( "root" )
10
- ) ;
8
+ < Router >
9
+ < ScrollToTop >
10
+ < App />
11
+ </ ScrollToTop >
12
+ </ Router > ,
13
+ document . getElementById ( 'root' )
14
+ ) ;
You can’t perform that action at this time.
0 commit comments