+
+ In this example, new items can be created using a mutation. The new item
+ will be optimistically added to the list in hopes that the server
+ accepts the item. If it does, the list is refetched with the true items
+ from the list. Every now and then, the mutation may fail though. When
+ that happens, the previous list of items is restored and the list is
+ again refetched from the server.
+
+
+
+ {queryInfo.isSuccess && (
+ <>
+
+ {/* The type of queryInfo.data will be narrowed because we check for isSuccess first */}
+ Updated At: {new Date(queryInfo.data.ts).toLocaleTimeString()}
+
+
+ {queryInfo.data.items.map(todo => (
+ - {todo.text}
+ ))}
+
+ {isFetching &&
Updating in background...
}
+ >
+ )}
+ {queryInfo.isLoading && 'Loading'}
+ {queryInfo.error?.message}
+
+ )
+}
diff --git a/examples/optimistic-updates-typescript/tsconfig.json b/examples/optimistic-updates-typescript/tsconfig.json
new file mode 100644
index 0000000000..1087618126
--- /dev/null
+++ b/examples/optimistic-updates-typescript/tsconfig.json
@@ -0,0 +1,26 @@
+{
+ "include": [
+ "./pages/**/*"
+ ],
+ "compilerOptions": {
+ "strict": true,
+ "esModuleInterop": true,
+ "lib": [
+ "dom",
+ "es2015"
+ ],
+ "jsx": "preserve",
+ "target": "es5",
+ "allowJs": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true,
+ "noEmit": true,
+ "module": "esnext",
+ "moduleResolution": "node",
+ "resolveJsonModule": true,
+ "isolatedModules": true
+ },
+ "exclude": [
+ "node_modules"
+ ]
+}