Skip to content

Commit

Permalink
chore: only render the top level to increase performance on larger JS…
Browse files Browse the repository at this point in the history
…ON (#69)

* chore: only render the top level to increase performance on larger JSON
  • Loading branch information
PatrickDinh authored May 27, 2024
1 parent d37199c commit 08aeb37
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/features/common/components/json-view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonView as ReactJsonView, allExpanded } from 'react-json-view-lite'
import { JsonView as ReactJsonView } from 'react-json-view-lite'
import 'react-json-view-lite/dist/index.css'
import styles from './json-view.module.css'
import { cn } from '../utils'
Expand Down Expand Up @@ -39,10 +39,14 @@ export function JsonView({ json }: { json: object }) {
<Button className={cn('absolute top-4 right-4')} onClick={copyJsonToClipboard}>
Copy
</Button>
<ReactJsonView data={json} shouldExpandNode={allExpanded} style={style} />
<ReactJsonView data={json} shouldExpandNode={shouldExpandNode} style={style} />
</div>
)
}
// Only render the top level because sometimes the object has too many children to render
const shouldExpandNode = (level: number) => {
return level < 1
}

export interface StyleProps {
container: string
Expand Down

0 comments on commit 08aeb37

Please sign in to comment.