I used the plugin generator to create a scaffold for a test plugin. Iām trying to convert the class component Main into a functional one, but getting this error in ESLint: " A decorated export must export a class declaration."
I donāt know what a ādecorated exportā is, but I think itās related to:
I was really confused by the generated example that datocms-plugin-generator created using an older version of React; its toolchain (webpack, babel, eslint, etc.) also seemed to ship with older defaults.
If anyone else is struggling with this, I ended up just using create-react-app with modern hooks and that worked much better.
In the plugin settings, I had to change the entry point to localhost:3000 (the create-react-app default) instead of 5000 (used in the plugin generator).
Note: That sample above only works for display, not yet for editing anything. I think the useEffect hook is also unnecessary there.
Iām still trying to figure out how to send data back to Dato asynchronously. plugin.setFieldValue() returns a promise⦠not sure how to resolve that with React states. Iāll update this if I figure it out.
The state (JSONData) keeps track of local state. useEffect loads the field value from Dato into the local state only once (because of the empty [] deps array).
Then, whenever something is updated by a human, I call sendJSONToDato instead of setJSONData directly. That makes an async call to Dato, waits for the promises to resolve, and then sets the local state.
It seems to work in basic cases. No error handling or conflict resolution, etc. though. If multiple editors try to work on the same record itāll probably blow up.
Thanks @roger, yes, we should really update our skeleton. Added in our TODO list, will update this thread as soon as itās ready.
By the way, whenever an editor starts editing a record the record is locked and other editors cannot edit it at the same time: Collaboration features - DatoCMS