When developing an app, specifically when doing frontend, we think and consider the best for the user experiencing our app. A technique called optimistic updating is available to us which we can make advantage to for our app's improvement in terms of desirability.
This is not limited specifically to React, it can be apply to any javascript (framework) with the client and server interactivity.
Optimistic updating is this:
We update the client data to reflect it to the frontend immediately, not awaiting for the server to fully processed that same data. Our app is optimistic even it didn't heard from the server yet. It trusted the return the server will provide once it is processed.
Example:
createData = (data) => {
const d = helpers.newDate(data);
this.setState({ dataList: this.state.dataList.concat(d) });
server.createData(d);
}
In this example, React's this.setState will automatic call the render() function and update the UI where dataList is displayed.
We then call the server.createData() communicating to the server to add the data to the dataList in server level.
Meaning, the user will see the update immediately on his/her screen even the server hasn't process it fully, or worst case didn't processed it because of error (When error happens, the update just don't persists).
The result, our app is more responsive than not using the optimistic update approach.
There's a caveat here. When using this technique, we make sure that the server restrictions in update must be the same with the update made locally. We cannot be optimistic if the server will process the data in a different manner we process it locally.