bhch / django-jsonform

A better, user-friendly JSON editing form field for Django admin. Also supports Postgres ArrayField.
https://django-jsonform.rtfd.io
BSD 3-Clause "New" or "Revised" License
307 stars 31 forks source link

Including the JS in our own bundle? #134

Open sergei-maertens opened 6 months ago

sergei-maertens commented 6 months ago

I see that the form field declares the media property which loads your react, react-dom and react-modal dependencies + the actual UI code.

We happen to already use react & react-modal in our (admin) application, so it would be cool if we could avoid loading those dependencies multiple times.

Do you have any pointers or documentation on how we could include your UI code in our own bundle? We use webpack for bundling. I can see that https://github.com/bhch/react-json-form is published to npm, but it only lists React v17 in the peer dependencies. Are there known issues with React 18?

bhch commented 6 months ago

I'll test it out with React 18 and update the dependencies.


To avoid loading the dependencies, you can subclass the JSONFormWidget and override the media method to remove those js file references which you don't need.


If you are going to include the underlying js library in your bundle, then you'll be responsible for rendering the widget yourself on relevant pages. You can find the complete guide in react-json-form docs: https://bhch.github.io/react-json-form/docs/usage/node/.

bhch commented 6 months ago

I've published a new version of react-json-form on npm which supports React 18.