CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
react-deps.js65 linesDownload Raw Back to src
1import * as React from "react";2 3// React.useInsertionEffect is not available in React <184// This hack fixes a transpilation issue on some apps5const useBuiltinInsertionEffect = React["useInsertion" + "Effect"];6 7export {8  useMemo,9  useRef,10  useState,11  useContext,12  createContext,13  isValidElement,14  cloneElement,15  createElement,16  Fragment,17  forwardRef,18} from "react";19 20// To resolve webpack 5 errors, while not presenting problems for native,21// we copy the approaches from https://github.com/TanStack/query/pull/356122// and https://github.com/TanStack/query/pull/360123// ~ Show this aging PR some love to remove the need for this hack:24//   https://github.com/facebook/react/pull/25231 ~25export { useSyncExternalStore } from "./use-sync-external-store.js";26 27// Copied from:28// https://github.com/facebook/react/blob/main/packages/shared/ExecutionEnvironment.js29const canUseDOM = !!(30  typeof window !== "undefined" &&31  typeof window.document !== "undefined" &&32  typeof window.document.createElement !== "undefined"33);34 35// Copied from:36// https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.ts37// "React currently throws a warning when using useLayoutEffect on the server.38// To get around it, we can conditionally useEffect on the server (no-op) and39// useLayoutEffect in the browser."40export const useIsomorphicLayoutEffect = canUseDOM41  ? React.useLayoutEffect42  : React.useEffect;43 44// useInsertionEffect is already a noop on the server.45// See: https://github.com/facebook/react/blob/main/packages/react-server/src/ReactFizzHooks.js46export const useInsertionEffect =47  useBuiltinInsertionEffect || useIsomorphicLayoutEffect;48 49// Userland polyfill while we wait for the forthcoming50// https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md51// Note: "A high-fidelity polyfill for useEvent is not possible because52// there is no lifecycle or Hook in React that we can use to switch53// .current at the right timing."54// So we will have to make do with this "close enough" approach for now.55export const useEvent = (fn) => {56  const ref = React.useRef([fn, (...args) => ref[0](...args)]).current;57  // Per Dan Abramov: useInsertionEffect executes marginally closer to the58  // correct timing for ref synchronization than useLayoutEffect on React 18.59  // See: https://github.com/facebook/react/pull/25881#issuecomment-135624436060  useInsertionEffect(() => {61    ref[0] = fn;62  });63  return ref[1];64};65