Skip to main content
Version: 5.x.x

Optimistic Approach

Optimistic approach allows us to make instant changes to the UI, before receiving data from the server. In this way, in the example, when removing a user, he is removed from the list immediately after clicking, which makes the application "faster" and more responsive to the actions of our users.


function UserTableRow({ user }) {
const [isDeleted, setDeleted] = useState(false);

const { submit, onSubmitRequestStart, onSubmitError, onSubmitSuccess, revalidate } = useSubmit(
deleteUser.setParams({ userId: }),

onSubmitRequestStart(() => {
// Set user row as deleted right when request starts

onSubmitError(() => {
// When it fails, recover state

onSubmitSuccess(() => {
// When it's successful, just revalidate users list to pull new page data
revalidate(new RegExp("/users"));

if (isDeleted) {
return null;

return (
<tr className="row">
<button onClick={() => submit()}>Delete</button>