CarlosNZ / json-edit-react

React component for editing/viewing JSON/object data
https://carlosnz.github.io/json-edit-react/
MIT License
183 stars 18 forks source link

Any plans on making a viewer-only? #106

Closed aconrad closed 2 months ago

aconrad commented 3 months ago

Thanks for your work on this tool, it's a pretty JSON renderer.

I need a viewer, not an editor. I'm currently passing restrict* props to false, which works. But I was wondering whether a viewer-only component (e.g. import { JsonViewer } from "json-edit-react";) would help trim the size of my final bundle. Thoughts?

CarlosNZ commented 3 months ago

Hey, thanks for your comments.

I hadn't really planned to do that. I'd be happy to export a different "Viewer" component, but that would just be a wrapper around the main component with preset props. So I don't think that would help with bundle size at all, since I wouldn't be making a separate codebase for it (and don't really have any desire to, to be honest).

jpainam commented 3 months ago

If you are looking for viewer-only, check this https://www.npmjs.com/package/react-json-tree

aconrad commented 3 months ago

If you are looking for viewer-only, check this https://www.npmjs.com/package/react-json-tree

I'll take a look, thanks. But is it as pretty as this one though? :)

aconrad commented 3 months ago

The lib react-json-tree is slightly larger according to bundlephobia.

https://bundlephobia.com/package/json-edit-react@1.15.8 https://bundlephobia.com/package/react-json-tree@0.19.0

But I suppose the real test should be looking at the size of the lib after tree-shaking.

CarlosNZ commented 3 months ago

How about just a single viewer prop, which would disable all editing capability, so syntax would be:

<JsonEditor data={myData} viewer />

It wouldn't really help with the bundle size though, as it wouldn't be a separate code base, it would just be a shorthand for manually adding all the disable editing props. Just wondering if people would find that useful, or if they're happy to just include the disable editing props?

aconrad commented 3 months ago

I think it's okay to leave it as is. I might fork the repo when I get a chance and experiment by ripping out the editing features and see how small we can get...

jpainam commented 2 months ago

I think it's okay to leave it as is. I might fork the repo when I get a chance and experiment by ripping out the editing features and see how small we can get...

It would be great if you could share it here too