PagePathNavTitle.tsx 1.4 KB

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