UNPKG

state-management-utilities

Version:
37 lines (36 loc) 1.35 kB
import React from "react"; import { useStyles } from "../providers/StylesProvider"; import { BigIntComponent } from "./BigInt"; import { BooleanComponent } from "./Boolean"; import { FunctionComponent } from "./Function"; import { NullComponent } from "./Null"; import { NumberComponent } from "./Number"; import { ObjectPrimary } from "./ObjectPrimary"; import { StringComponent } from "./String"; import { SymbolComponent } from "./Symbol"; import { UndefinedComponent } from "./Undefined"; export function DetectType({ data, name }) { const styles = useStyles(); const type = React.useMemo(() => { if (data === null) return "null"; return typeof data; }, [data]); const Component = React.useMemo(() => TYPES[type], [type]); return (React.createElement("div", { className: styles["data-visualizer-row"] }, !name ? null : (React.createElement("div", { className: styles["data-visualizer-name"] }, name, ":")), React.createElement(Component, { data: data }))); } const TYPES = Object.freeze({ undefined: UndefinedComponent, function: FunctionComponent, boolean: BooleanComponent, bigint: BigIntComponent, number: NumberComponent, object: ObjectPrimary, string: StringComponent, symbol: SymbolComponent, null: NullComponent, });