PagePathNavTitle.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { useState } from 'react';
  2. import withLoadingProps from 'next-dynamic-loading-props';
  3. import dynamic from 'next/dynamic';
  4. import { useIsomorphicLayoutEffect } from 'usehooks-ts';
  5. import { PagePathNav } from '../PagePathNav';
  6. import type { PagePathNavLayoutProps } from '../PagePathNav';
  7. import styles from './PagePathNavTitle.module.scss';
  8. const moduleClass = styles['grw-page-path-nav-title'] ?? '';
  9. const PagePathNavSticky = withLoadingProps<PagePathNavLayoutProps>(useLoadingProps => dynamic(
  10. () => import('~/client/components/PagePathNavSticky').then(mod => mod.PagePathNavSticky),
  11. {
  12. ssr: false,
  13. loading: () => {
  14. // eslint-disable-next-line react-hooks/rules-of-hooks
  15. const props = useLoadingProps();
  16. return <PagePathNav {...props} />;
  17. },
  18. },
  19. ));
  20. /**
  21. * Switch PagePathNav and PagePathNavSticky
  22. * @returns
  23. */
  24. export const PagePathNavTitle = (props: PagePathNavLayoutProps): JSX.Element => {
  25. const [isClient, setClient] = useState(false);
  26. useIsomorphicLayoutEffect(() => {
  27. setClient(true);
  28. }, []);
  29. return isClient
  30. ? <PagePathNavSticky {...props} className={moduleClass} latterLinkClassName="fs-2" />
  31. : <PagePathNav {...props} className={moduleClass} latterLinkClassName="fs-2" />;
  32. };