Skip to content

Commit 31a31da

Browse files
committed
docs(transition): Fix transitionTo documentation to use useEffect
1 parent 1f1a04e commit 31a31da

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/transition/src/types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ export interface TransitionHookReturnValue<E extends HTMLElement>
421421
* @example
422422
* Simple Example
423423
* ```tsx
424+
* import { ReactElement, useEffect, useRef } from "react";
425+
* import { useCSSTransition } from "@react-md/transition";
426+
* import { useRouter } from "react-router-dom";
424427
*
425428
* function Example(): ReactElement {
426429
* const { pathname } = useRouter();
@@ -430,11 +433,15 @@ export interface TransitionHookReturnValue<E extends HTMLElement>
430433
* classNames: "some-enter-transition",
431434
* });
432435
*
433-
* const prevPathname = useRef(pathname);
434-
* if (pathname !== prevPathname.current) {
436+
* useEffect(() => {
437+
* // Do not trigger transition on first load.
438+
* if (prevPathname.current === pathname) {
439+
* return;
440+
* }
441+
*
435442
* prevPathname.current = pathname;
436443
* transitionTo("enter");
437-
* }
444+
* }, [pathname, transitionTo]);
438445
*
439446
* return <div {...elementProps}>{content}</div>;
440447
* }

0 commit comments

Comments
 (0)