Skip to content

Commit

Permalink
docs(transition): Fix transitionTo documentation to use useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Nov 25, 2021
1 parent 1f1a04e commit 31a31da
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/transition/src/types.ts
Expand Up @@ -421,6 +421,9 @@ export interface TransitionHookReturnValue<E extends HTMLElement>
* @example
* Simple Example
* ```tsx
* import { ReactElement, useEffect, useRef } from "react";
* import { useCSSTransition } from "@react-md/transition";
* import { useRouter } from "react-router-dom";
*
* function Example(): ReactElement {
* const { pathname } = useRouter();
Expand All @@ -430,11 +433,15 @@ export interface TransitionHookReturnValue<E extends HTMLElement>
* classNames: "some-enter-transition",
* });
*
* const prevPathname = useRef(pathname);
* if (pathname !== prevPathname.current) {
* useEffect(() => {
* // Do not trigger transition on first load.
* if (prevPathname.current === pathname) {
* return;
* }
*
* prevPathname.current = pathname;
* transitionTo("enter");
* }
* }, [pathname, transitionTo]);
*
* return <div {...elementProps}>{content}</div>;
* }
Expand Down

1 comment on commit 31a31da

@vercel
Copy link

@vercel vercel bot commented on 31a31da Nov 25, 2021

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.