redux-devtools/packages/react-json-tree/src/JSONArrayNode.tsx
Nathan Bierema 81926f3212
Remove UNSAFE methods from react-json-tree (#1288)
* Remove UNSAFE method from JSONTree

* Bump peer dep

* Fix types

* Remove proptypes

* Remove unused

* shouldExpandNode => shouldExpandNodeInitially

* Cleanup

* Update usages

* Tighten types

* Create four-parrots-poke.md

* Format

* Fix inspector-monitor types

* Fix log-monitor types

* Fix rtk-query-monitor types

* Fix type
2023-01-04 23:17:44 -05:00

31 lines
812 B
TypeScript

import React from 'react';
import JSONNestedNode from './JSONNestedNode';
import type { CommonInternalProps } from './types';
// Returns the "n Items" string for this node,
// generating and caching it if it hasn't been created yet.
function createItemString(data: unknown) {
return `${(data as unknown[]).length} ${
(data as unknown[]).length !== 1 ? 'items' : 'item'
}`;
}
interface Props extends CommonInternalProps {
data: unknown;
nodeType: string;
}
// Configures <JSONNestedNode> to render an Array
export default function JSONArrayNode({ data, ...props }: Props) {
return (
<JSONNestedNode
{...props}
data={data}
nodeType="Array"
nodeTypeIndicator="[]"
createItemString={createItemString}
expandable={(data as unknown[]).length > 0}
/>
);
}