All files / utils react.js

0% Statements 0/3
0% Branches 0/8
0% Functions 0/3
0% Lines 0/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                                             
/*
 * Copyright (c) 2022-2023 Braun Nathanael
 *
 * This project is dual licensed under one of the following licenses:
 * - Creative Commons Attribution-NoDerivatives 4.0 International License.
 * - GNU AFFERO GENERAL PUBLIC LICENSE Version 3
 *
 * You should have received a copy of theses licenses along with this work.
 * If not, see <http://creativecommons.org/licenses/by-nd/4.0/> or <http://www.gnu.org/licenses/agpl-3.0.txt>.
 */
 
 
/**
 * React component type detection helpers used by Node to decide how to pass the
 * DOM node ref to a child. Class components accept the standard `ref` prop directly;
 * functional components require either forwardRef or a named prop (e.g. `nodeRef`).
 */
export function isClassComponent(component) {
    return (
        typeof component === 'function' &&
        !!component.prototype.isReactComponent
    )
}
export function isFunctionalComponent(Component) {
    return (
        typeof Component === 'function' // can be various things
        && !(
        Component.prototype // native arrows don't have prototypes
        && Component.prototype.isReactComponent // special property
        )
    );
}
 
export function isReactComponent(component) {
    return (
        isClassComponent(component) ||
        isFunctionalComponent(component)
    )
}