Skip to content

Commit

Permalink
creating withFallback HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
RmnRss committed Sep 15, 2020
1 parent 64cd604 commit acba97d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hocs/withFallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useRouter } from "next/router";
import styled from "styled-components";
import LoadingAnimation from "../components/LoadingAnimation";

const Center = styled.div`
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
`;

/**
* HOC for statically rendered page with fallback activated
* @param {} WrappedComponent
*/
export default function withFallback(WrappedComponent) {
const withFallbackWrapper = (props) => {
const router = useRouter();

if (router.isFallback) {
return (
<Center>
<LoadingAnimation message={"Loading..."} />
</Center>
);
}

return <WrappedComponent {...props} />;
};

return withFallbackWrapper;
}

0 comments on commit acba97d

Please sign in to comment.