REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 1.52 KB
Close
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/use-memo-one/src/index.js
Text
Base64
// @flow import { useRef, useState, useEffect } from 'react'; import areInputsEqual from './are-inputs-equal'; type Cache<T> = {| inputs: ?(mixed[]), result: T, |}; export function useMemoOne<T>( // getResult changes on every call, getResult: () => T, // the inputs array changes on every call inputs?: mixed[], ): T { // using useState to generate initial value as it is lazy const initial: Cache<T> = useState(() => ({ inputs, result: getResult(), }))[0]; const isFirstRun = useRef<boolean>(true); const committed = useRef<Cache<T>>(initial); // persist any uncommitted changes after they have been committed const useCache: boolean = isFirstRun.current || Boolean( inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs), ); // create a new cache if required const cache: Cache<T> = useCache ? committed.current : { inputs, result: getResult(), }; // commit the cache useEffect(() => { isFirstRun.current = false; committed.current = cache; }, [cache]); return cache.result; } export function useCallbackOne<T: Function>( // getResult changes on every call, callback: T, // the inputs array changes on every call inputs?: mixed[], ): T { return useMemoOne(() => callback, inputs); } // Aliased exports // A drop in replacement for useMemo and useCallback that plays // very well with eslint-plugin-react-hooks export const useMemo = useMemoOne; export const useCallback = useCallbackOne;
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 2
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
are-inputs-equal.js
530 B
lrw-r--r--
2026-02-28 00:26:56
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
index.js
1.52 KB
lrw-r--r--
2026-02-28 00:27:08
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).