@dark-engine/core
Version:
The lightweight and powerful UI rendering engine without dependencies and written in TypeScript (Browser, Node.js, Android, iOS, Windows, Linux, macOS)
31 lines (30 loc) • 961 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
exports.useRef = exports.applyRef = exports.detectIsMutableRef = void 0;
const utils_1 = require('../utils');
const use_memo_1 = require('../use-memo');
function detectIsMutableRef(ref) {
if (!(0, utils_1.detectIsObject)(ref) || (0, utils_1.detectIsNull)(ref)) return false;
const mutableRef = ref;
for (const key in mutableRef) {
if (key === 'current' && mutableRef.hasOwnProperty(key)) {
return true;
}
}
return false;
}
exports.detectIsMutableRef = detectIsMutableRef;
function applyRef(ref, current) {
if ((0, utils_1.detectIsFunction)(ref)) {
ref(current);
} else if (detectIsMutableRef(ref)) {
ref.current = current;
}
}
exports.applyRef = applyRef;
function useRef(initialValue = null) {
const ref = (0, use_memo_1.useMemo)(() => ({ current: initialValue }), []);
return ref;
}
exports.useRef = useRef;
//# sourceMappingURL=ref.js.map