react/packages/react-devtools-shared/src/devtools/views/Components/HocBadges.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-08-28 01:54:01 +08:00
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import * as React from 'react';
2019-08-14 08:58:03 +08:00
import {
ElementTypeForwardRef,
ElementTypeMemo,
} from 'react-devtools-shared/src/types';
import styles from './HocBadges.css';
2019-08-14 08:58:03 +08:00
import type {Element} from './types';
type Props = {|
element: Element,
|};
2019-08-14 08:58:03 +08:00
export default function HocBadges({element}: Props) {
const {hocDisplayNames, type} = ((element: any): Element);
let typeBadge = null;
if (type === ElementTypeMemo) {
typeBadge = 'Memo';
} else if (type === ElementTypeForwardRef) {
typeBadge = 'ForwardRef';
}
if (hocDisplayNames === null && typeBadge === null) {
return null;
}
return (
<div className={styles.HocBadges}>
{typeBadge !== null && <div className={styles.Badge}>{typeBadge}</div>}
{hocDisplayNames !== null &&
hocDisplayNames.map(hocDisplayName => (
<div key={hocDisplayName} className={styles.Badge}>
{hocDisplayName}
</div>
))}
</div>
);
}