0283f4926e
Each is a self-contained rewrite of syntax React Compiler cannot lower: - `??=` -> an explicit null check - dynamic `import()` -> a module-scope loader - complex default parameter values -> module-scope consts - reassigned destructured parameters -> locals - functions used above their own declaration -> reordered - counters mutated inside a callback -> loop index or a local object - optional chains in a ternary test -> a hoisted const - a computed key in a destructuring pattern -> an omitKey helper - manual useMemo/useCallback the compiler cannot preserve -> deleted - exhaustive-deps suppressions -> useEffectEvent Skipped components: 125 -> 102. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
31 lines
914 B
TypeScript
31 lines
914 B
TypeScript
import {init} from 'emoji-mart'
|
|
|
|
/**
|
|
* Only load the emoji picker data once per page load.
|
|
*/
|
|
let loadRequested = false
|
|
|
|
/**
|
|
* Preloads emoji-mart data so the picker renders instantly when opened.
|
|
*
|
|
* Returns a function that can be called manually to trigger preloading (e.g.
|
|
* on hover). When `immediate` is `true`, preloading starts on mount.
|
|
*
|
|
* Data is only fetched once per page load — subsequent calls are no-ops.
|
|
*
|
|
* @see {@link https://github.com/missive/emoji-mart/blob/16978d04a766eec6455e2e8bb21cd8dc0b3c7436/README.md?plain=1#L194 | emoji-mart preloading docs}
|
|
*/
|
|
async function loadEmojiData() {
|
|
if (loadRequested) return
|
|
loadRequested = true
|
|
try {
|
|
const data = (await import('@emoji-mart/data')).default
|
|
init({data})
|
|
} catch (e) {}
|
|
}
|
|
|
|
export function useWebPreloadEmoji({immediate}: {immediate?: boolean} = {}) {
|
|
if (immediate) loadEmojiData()
|
|
return loadEmojiData
|
|
}
|