vendredi 24 juin 2016

What is the common way to handle successful REST POST operation in UI using React and Redux

I have a Thread component responsible to render messages of the specific thread and a component to submit a new message. Thread component's state is managed by Redux, which provides asynchronous actions like FETCH_MESSAGES and POST_MESSAGE. Below is the simplified pseudo-code.

class Thread {
  messages: [] // This is actually a prop connected to Redux
  render = () => {
    messages.map(messageComponent)
    <SubmitMessageComponent />
  }
}

What is the common way to handle successful POST operation of new Message in the UI, when server sends the object back with id? Is it safe to push that object to the array of earlier fetched messages or should I fetch all messages again to ensure consistency? First operation seems efficient but disjointed. I'm considered about handling concurrent REST API operations from different sources properly. Fetching everything all over again would always ensure the consistency of the state, but would be redundant performance wise (Imagine there are near infinite amount of messages)

Is there de facto way to deal with create operation in web application user interface?

Aucun commentaire:

Enregistrer un commentaire