emoji-picker-element/src/picker/utils/thunk.js

13 lines
254 B
JavaScript
Raw Normal View History

2020-06-01 03:05:51 +02:00
// Run a function once, then cache the result and return the cached result thereafter
export function thunk (func) {
let cached
let runOnce
return () => {
if (!runOnce) {
cached = func()
runOnce = true
}
return cached
}
}