You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
385 B
JavaScript

"use strict";
const React = require("react");
module.exports = function useLazyRef(initializer) {
let ref = React.useRef({ initialized: false, value: undefined });
if (ref.current.initialized === false) {
ref.current.value = {
// We mirror the standard useRef structure here
current: initializer()
};
ref.current.initializer = true;
}
return ref.current.value;
};