From 13780f390a668163504d245f88794206d458f199 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Wed, 24 May 2023 17:24:54 +0200 Subject: [PATCH] fix: add react v17 `useTransition` polyfill (#6618) --- src/components/LibraryMenuSection.tsx | 3 ++- src/hooks/useTransition.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/hooks/useTransition.ts diff --git a/src/components/LibraryMenuSection.tsx b/src/components/LibraryMenuSection.tsx index d1af8548..b6866e1e 100644 --- a/src/components/LibraryMenuSection.tsx +++ b/src/components/LibraryMenuSection.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useState, useTransition } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import { LibraryUnit } from "./LibraryUnit"; import { LibraryItem } from "../types"; import Stack from "./Stack"; @@ -6,6 +6,7 @@ import clsx from "clsx"; import { ExcalidrawElement, NonDeleted } from "../element/types"; import { useAtom } from "jotai"; import { libraryItemSvgsCache } from "../hooks/useLibraryItemSvg"; +import { useTransition } from "../hooks/useTransition"; const ITEMS_PER_ROW = 4; const ROWS_RENDERED_PER_BATCH = 6; diff --git a/src/hooks/useTransition.ts b/src/hooks/useTransition.ts new file mode 100644 index 00000000..bb107edb --- /dev/null +++ b/src/hooks/useTransition.ts @@ -0,0 +1,9 @@ +import React, { useCallback } from "react"; + +/** noop polyfill for v17. Subset of API available */ +function useTransitionPolyfill() { + const startTransition = useCallback((callback: () => void) => callback(), []); + return [false, startTransition] as const; +} + +export const useTransition = React.useTransition || useTransitionPolyfill;