misc_pterodactyl-panel/resources/scripts/TransitionRouter.tsx
Dane Everitt f144ba8394
Don't enter d i s c o m o d e when first opening the page; closes #2190
This was caused by the location.key being undefined when the page first renders (for some reason), and therefore the fade component just kept re-rendering since it wasn't using a unique key.
2020-08-19 21:30:45 -07:00

35 lines
983 B
TypeScript

import React, { useRef } from 'react';
import { Route } from 'react-router';
import { SwitchTransition } from 'react-transition-group';
import Fade from '@/components/elements/Fade';
import styled from 'styled-components/macro';
import tw from 'twin.macro';
import v4 from 'uuid/v4';
const StyledSwitchTransition = styled(SwitchTransition)`
${tw`relative`};
& section {
${tw`absolute w-full top-0 left-0`};
}
`;
const TransitionRouter: React.FC = ({ children }) => {
const uuid = useRef(v4()).current;
return (
<Route
render={({ location }) => (
<StyledSwitchTransition>
<Fade timeout={150} key={location.key || uuid} in appear unmountOnExit>
<section>
{children}
</section>
</Fade>
</StyledSwitchTransition>
)}
/>
);
};
export default TransitionRouter;