feat(react-json-tree): Add keyPath to getItemString (#694)

This commit is contained in:
Josh Hunt 2020-12-22 16:15:29 +00:00 committed by GitHub
parent a46b43209d
commit 85b4b0fb04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -102,14 +102,14 @@ You can pass `getItemString` to customize the way arrays, objects, and iterable
By default, it'll be:
```jsx
<JSONTree getItemString={(type, data, itemType, itemString)
<JSONTree getItemString={(type, data, itemType, itemString, keyPath)
=> <span>{itemType} {itemString}</span>}
```
But if you pass the following:
```jsx
const getItemString = (type, data, itemType, itemString)
const getItemString = (type, data, itemType, itemString, keyPath)
=> (<span> // {type}</span>);
```

View File

@ -193,7 +193,8 @@ export default class JSONNestedNode extends React.Component<Props, State> {
nodeType,
data,
itemType,
createItemString(data, collectionLimit)
createItemString(data, collectionLimit),
keyPath
);
const stylingArgs = [keyPath, nodeType, expanded, expandable] as const;

View File

@ -35,7 +35,8 @@ interface JSONNestedNodeCircularPropsPassedThroughJSONTree {
nodeType: string,
data: any,
itemType: React.ReactNode,
itemString: string
itemString: string,
keyPath: (string | number)[]
) => React.ReactNode;
postprocessValue: (value: any) => any;
isCustomNode: (value: any) => boolean;