Skip to content

Commit 08aeb37

Browse files
authored
chore: only render the top level to increase performance on larger JSON (#69)
* chore: only render the top level to increase performance on larger JSON
1 parent d37199c commit 08aeb37

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/features/common/components/json-view.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JsonView as ReactJsonView, allExpanded } from 'react-json-view-lite'
1+
import { JsonView as ReactJsonView } from 'react-json-view-lite'
22
import 'react-json-view-lite/dist/index.css'
33
import styles from './json-view.module.css'
44
import { cn } from '../utils'
@@ -39,10 +39,14 @@ export function JsonView({ json }: { json: object }) {
3939
<Button className={cn('absolute top-4 right-4')} onClick={copyJsonToClipboard}>
4040
Copy
4141
</Button>
42-
<ReactJsonView data={json} shouldExpandNode={allExpanded} style={style} />
42+
<ReactJsonView data={json} shouldExpandNode={shouldExpandNode} style={style} />
4343
</div>
4444
)
4545
}
46+
// Only render the top level because sometimes the object has too many children to render
47+
const shouldExpandNode = (level: number) => {
48+
return level < 1
49+
}
4650

4751
export interface StyleProps {
4852
container: string

0 commit comments

Comments
 (0)