uiwjs / react-json-view

A React component for displaying and editing javascript arrays and JSON objects.
https://uiwjs.github.io/react-json-view/
MIT License
188 stars 11 forks source link

In JsonView.KeyName, `keys` is sometimes undefined (v2) #46

Closed emilyo9264 closed 5 months ago

emilyo9264 commented 5 months ago
import JsonView from "@uiw/react-json-view";

const example = {
  nestedArray: [],
  object: {},
};

export default function App() {
  return (
    <JsonView value={example}>
      <JsonView.KeyName
        as="span"
        render={({ style, onClick, ...props }, { keyName, keys }) => {
          console.log(keyName, keys); // keys undefined
          return (
            <span {...props} style={{ ...style, backgroundColor: "red" }} />
          );
        }}
      />
    </JsonView>
  );
}

Expected from the console:

nestedArray ["nestedArray"]
object ["object"]

Actual:

nestedArray undefined
object undefined

Code sandbox minimal example to reproduce: https://codesandbox.io/p/sandbox/lingering-butterfly-4sc9kd

jaywcjlove commented 5 months ago

@emilyo9264 Upgrade v2.0.0-alpha.22