-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.jsx
39 lines (36 loc) · 1.33 KB
/
Layout.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Head from 'next/head';
import Navbar from './Navbar';
import styles from '../../styles/Layout.module.scss';
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import { useDispatch, useSelector } from 'react-redux';
import { setIsFetching } from '../../redux/notesReducer';
import { Spin } from 'antd';
import ScrollToTop from 'react-scroll-to-top';
export default function Layout({ children, title }) {
const router = useRouter();
const dispatch = useDispatch();
const state = useSelector((state) => state);
useEffect(() => {
router.events.on('routeChangeStart', () => dispatch(setIsFetching(true)));
router.events.on('routeChangeComplete', () => dispatch(setIsFetching(false)));
router.events.on('routeChangeError', () => dispatch(setIsFetching(false)));
return () => {
router.events.off('routeChangeStart', () => dispatch(setIsFetching(true)));
router.events.off('routeChangeComplete', () => dispatch(setIsFetching(false)));
router.events.off('routeChangeError', () => dispatch(setIsFetching(false)));
};
}, []);
return (
<div className={styles.container}>
<Head>
<title>{title}</title>
</Head>
<Navbar />
<Spin size="large" spinning={state.isFetching}>
{children}
</Spin>
<ScrollToTop top={150} smooth />
</div>
);
}