From 807116a60263944604b625d323a8a51f3d3a50fd Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 24 Sep 2022 12:37:59 +0100 Subject: [PATCH] useEvent --- .../components/MDX/Sandpack/NavigationBar.tsx | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/beta/src/components/MDX/Sandpack/NavigationBar.tsx b/beta/src/components/MDX/Sandpack/NavigationBar.tsx index acc972fb0..81c48b0fa 100644 --- a/beta/src/components/MDX/Sandpack/NavigationBar.tsx +++ b/beta/src/components/MDX/Sandpack/NavigationBar.tsx @@ -4,10 +4,9 @@ import { useRef, - useInsertionEffect, - useCallback, useState, useEffect, + experimental_useEvent as useEvent, Fragment, } from 'react'; import cn from 'classnames'; @@ -22,19 +21,6 @@ import {DownloadButton} from './DownloadButton'; import {IconChevron} from '../../Icon/IconChevron'; import {Listbox} from '@headlessui/react'; -// TODO: Replace with real useEvent. -export function useEvent(fn: any): any { - const ref = useRef(null); - useInsertionEffect(() => { - ref.current = fn; - }, [fn]); - return useCallback((...args: any) => { - const f = ref.current!; - // @ts-ignore - return f(...args); - }, []); -} - const getFileName = (filePath: string): string => { const lastIndexOfSlash = filePath.lastIndexOf('/'); return filePath.slice(lastIndexOfSlash + 1);