Re-rendering front end to automatically display updates from local API payload.update #3109
Replies: 1 comment 1 reply
-
Would like to see this as well. I have a few collections that have relations to other collections. If I edit/update the relationship field collection (where the side drawer opens up) and save it, it would be nice if there was a way to refresh the original collections data. This is an issue because if the saved collection modifies the original collection, and the user saves the original collection, it will overwrite the collections data with whatever data was in the current state. This could also be a problem if the collection is updated elsewhere (Rest API for example) and the user saves the collection after it's already loaded. It would overwrite the previous data with the stale form data. Assuming Payload doesn't already have server-sent events or other strategies built in already, you would likely have to build a custom socket.io server within payload. You could have it fire events after every "afterChange" hook and update your front-end form fields using I came up with an alternative solution for my problem if it helps anyone. I made a custom save button that checks for updated data and warns the user if it's different. When the doc loads (or when save button is mounted more specifically), it will store the documents data in state. Then when the user saves the doc, it will fetch the most recent data and compare it to the data on load. This way, if an API updates a user's "Orders" while an admin is editing said user, the admin would be warned if they tried to save the user doc.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have several collections whose fields get updated via the local API when changes are made in other collections. Is there a simple way to have the collections that were updated re-render to display the changes without manually refreshing? I also have some custom react components that I would like the same to happen with, would the custom components need to be updated via server-sent events or is there a strategy provided by payload?
Beta Was this translation helpful? Give feedback.
All reactions