I'm currently working with data such that two users may be using concurrently. I need User B's app page to render the changes User A made to the data after he/she saves it to the database. I figured I could use mongoose's change stream functionality to accomplish this.
Backend: Express, MongoDB
Integration: Axios
Frontend: React.js with Redux
I know how to call to the back end from the front end by sending a get/post/put request through Axios, but I don't know how to send data to the front end without an API call.
Example code
const listenToData = async () => {
Person.watch().on('change', data => {
//callback function: what to do here to send changes to the front end?
}
}
Would the above code go in my API? Would it go in the Redux Actions of the front end? What do I do after the 'on change' event is triggered to send the new data to the front end of the user? Is there a way I can broadcast the event to the front end and take care of it there?
Is change streams not enough, will I need something like WebSocket?