diff options
author | dan <dan.abramov@gmail.com> | 2024-11-01 22:17:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-01 22:17:05 +0000 |
commit | 7111e38cd48c1c7e2b35ae978708fcb7a60a5dd7 (patch) | |
tree | c83c83ff23f6095bf581c92db6df743a16255181 /lib | |
parent | 3eb531b00004f3752ec825350df1943c33028ac1 (diff) | |
download | voidsky-7111e38cd48c1c7e2b35ae978708fcb7a60a5dd7.tar.zst |
This reverts commit 1fc684aaef6dd851b4d6c9a23673fcf4e7170722.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/react-compiler-runtime/index.js | 21 | ||||
-rw-r--r-- | lib/react-compiler-runtime/package.json | 9 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/react-compiler-runtime/index.js b/lib/react-compiler-runtime/index.js new file mode 100644 index 000000000..44f80e0c9 --- /dev/null +++ b/lib/react-compiler-runtime/index.js @@ -0,0 +1,21 @@ +const React = require('react') +const $empty = Symbol.for('react.memo_cache_sentinel') +/** + * DANGER: this hook is NEVER meant to be called directly! + * + * Note that this is a temporary userspace implementation of this function + * from React 19. It is not as efficient and may invalidate more frequently + * than the official API. Please upgrade to React 19 as soon as you can. + **/ +export function c(size) { + // eslint-disable-next-line react-hooks/rules-of-hooks + return React.useState(() => { + const $ = new Array(size) + for (let ii = 0; ii < size; ii++) { + $[ii] = $empty + } + // @ts-ignore + $[$empty] = true + return $ + })[0] +} diff --git a/lib/react-compiler-runtime/package.json b/lib/react-compiler-runtime/package.json new file mode 100644 index 000000000..cb8f78bd5 --- /dev/null +++ b/lib/react-compiler-runtime/package.json @@ -0,0 +1,9 @@ +{ + "name": "react-compiler-runtime", + "version": "0.0.1", + "license": "MIT", + "main": "index.js", + "peerDependencies": { + "react": "^18.2.0" + } +} \ No newline at end of file |