@material-ui/core
Version:
React components that implement Google's Material Design.
29 lines (27 loc) • 829 B
JavaScript
import React from 'react';
export function isMuiElement(element, muiNames) {
return React.isValidElement(element) && muiNames.indexOf(element.type.muiName) !== -1;
} // TODO: Make it private only in v5
export function setRef(ref, value) {
if (typeof ref === 'function') {
ref(value);
} else if (ref) {
ref.current = value;
}
}
export function useForkRef(refA, refB) {
/**
* This will create a new function if the ref props change and are defined.
* This means react will call the old forkRef with `null` and the new forkRef
* with the ref. Cleanup naturally emerges from this behavior
*/
return React.useMemo(() => {
if (refA == null && refB == null) {
return null;
}
return refValue => {
setRef(refA, refValue);
setRef(refB, refValue);
};
}, [refA, refB]);
}