@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)
26 lines (25 loc) • 736 B
JavaScript
import { detectIsObject, detectIsNull, detectIsFunction } from '../utils';
import { useMemo } from '../use-memo';
function detectIsMutableRef(ref) {
if (!detectIsObject(ref) || detectIsNull(ref)) return false;
const mutableRef = ref;
for (const key in mutableRef) {
if (key === 'current' && mutableRef.hasOwnProperty(key)) {
return true;
}
}
return false;
}
function applyRef(ref, current) {
if (detectIsFunction(ref)) {
ref(current);
} else if (detectIsMutableRef(ref)) {
ref.current = current;
}
}
function useRef(initialValue = null) {
const ref = useMemo(() => ({ current: initialValue }), []);
return ref;
}
export { detectIsMutableRef, applyRef, useRef };
//# sourceMappingURL=ref.js.map