UNPKG

902 BJavaScriptView Raw
1import { isMemo, isFragment } from 'react-is';
2export function toArray(candidate) {
3 if (candidate === undefined || candidate === false) return [];
4 return Array.isArray(candidate) ? candidate : [candidate];
5}
6// eslint-disable-next-line @typescript-eslint/ban-types
7function shouldConstruct(Component) {
8 const prototype = Component.prototype;
9 return !!(prototype && prototype.isReactComponent);
10}
11// https://github.com/facebook/react/blob/ce13860281f833de8a3296b7a3dad9caced102e9/packages/react-reconciler/src/ReactFiber.new.js#L225
12function isSimpleFunctionComponent(type) {
13 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
14}
15export function isSafeSetRefComponent(component) {
16 if (isFragment(component)) return false;
17 if (isMemo(component)) return isSafeSetRefComponent(component.type);
18 return !isSimpleFunctionComponent(component.type);
19}
\No newline at end of file