Skip to content

Commit

Permalink
chore(website): useLayoutEffect for page transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Apr 1, 2022
1 parent 60a8825 commit 638c8ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/documentation/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactElement, ReactNode } from "react";
import { useEffect, useRef, useState } from "react";
import { useEffect, useRef, useState, useLayoutEffect } from "react";
import type { ConfiguredIcons } from "@react-md/icon";
import type { LayoutConfiguration } from "@react-md/layout";
import {
Expand Down Expand Up @@ -95,7 +95,7 @@ export default function Layout({

const prevPathname = useRef(pathname);
const { elementProps, transitionTo } = useCrossFadeTransition();
useEffect(() => {
useLayoutEffect(() => {
if (prevPathname.current === pathname) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/documentation/src/guides/configuring-your-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ cross fade transition on route changes with the `useCrossFadeTransition` hook.

```diff
-import { ReactElement } from "react";
+import { ReactElement, useRef } from "react";
+import { ReactElement, useRef, useLayoutEffect } from "react";
import { Layout, useLayoutNavigation } from "@react-md/layout";
+import { useCrossFadeTransition } from "@react-md/transition";
import { useLocation, Link } from "react-router-dom";
Expand All @@ -346,7 +346,7 @@ cross fade transition on route changes with the `useCrossFadeTransition` hook.
const { pathname } = useLocation();
+ const prevPathname = useRef(pathname);
+ const { elementProps, transitionTo } = useCrossFadeTransition();
+ useEffect(() => {
+ useLayoutEffect(() => {
+ if (pathname === prevPathname.current) {
+ return
+ }
Expand Down
4 changes: 2 additions & 2 deletions packages/transition/src/useCrossFadeTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface CrossFadeTransitionHookOptions<E extends HTMLElement>
* @example
* New Page Transition with `@react-md/layout`
* ```tsx
* import { ReactElement, ReactNode, useEffect } from "react";
* import { ReactElement, ReactNode, useLayoutEffect } from "react";
* import { useLocation } from "react-router-dom":
* import { Layout, useLayoutNavigation } from "@react-md/layout";
* import { useCrossFadeTransition } from "@react-md/transition";
Expand All @@ -84,7 +84,7 @@ export interface CrossFadeTransitionHookOptions<E extends HTMLElement>
* const { elementProps, transitionTo } = useCrossFadeTransition();
*
* const prevPathname = useRef(pathname);
* useEffect(() => {
* useLayoutEffect(() => {
* if (prevPathname.current === pathname) {
* return
* }
Expand Down

1 comment on commit 638c8ec

@vercel
Copy link

@vercel vercel bot commented on 638c8ec Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.