Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import { useState, useEffect } from "react";
  2. import Router from "next/router";
  3.  
  4. const Layout = props => {
  5. const [isLoading, setIsLoading] = useState(false);
  6.  
  7. useEffect(() => {
  8. const updateLoadingStatus = () => setIsLoading(!isLoading);
  9.  
  10. Router.events.on("routeChangeStart", updateLoadingStatus);
  11. Router.events.on("routeChangeComplete", updateLoadingStatus);
  12.  
  13. return () => {
  14. Router.events.off("routeChangeStart", updateLoadingStatus);
  15. Router.events.off("routeChangeComplete", updateLoadingStatus);
  16. };
  17. }, [isLoading]);
  18.  
  19. return (
  20. <div>
  21. { isLoading ? <p>Loading...</p> : props.children }
  22. </div>
  23. );
  24. }
  25.  
  26. export default Layout;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement