Comparing version 5.0.2 to 5.1.0
@@ -30,3 +30,5 @@ "use strict"; | ||
var query = function () { return _this.zodios.get(path, config); }; | ||
return (0, react_query_1.useQuery)(keys, query, queryOptions); | ||
var queryClient = (0, react_query_1.useQueryClient)(); | ||
var invalidate = function () { return queryClient.invalidateQueries(keys); }; | ||
return __assign({ invalidate: invalidate }, (0, react_query_1.useQuery)(keys, query, queryOptions)); | ||
}; | ||
@@ -33,0 +35,0 @@ ZodiosHooks.prototype.useMutation = function (method, path, mutationOptions) { |
{ | ||
"name": "zodios", | ||
"description": "Typescript API client with autocompletion and zod validations", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"main": "lib/index.js", | ||
@@ -43,3 +43,3 @@ "typings": "lib/index.d.ts", | ||
"@types/node": "17.0.17", | ||
"@types/react": "18.0.1", | ||
"@types/react": "18.0.5", | ||
"axios": "0.26.1", | ||
@@ -49,3 +49,3 @@ "express": "4.17.3", | ||
"react": "18.0.0", | ||
"react-query": "3.34.19", | ||
"react-query": "3.34.20", | ||
"rimraf": "3.0.2", | ||
@@ -52,0 +52,0 @@ "ts-jest": "27.1.4", |
@@ -51,2 +51,4 @@ <h1 align="center">Zodios</h1> | ||
Here is an example of API declaration with Zodios. | ||
```typescript | ||
@@ -71,2 +73,6 @@ import { Zodios } from "zodios"; | ||
); | ||
``` | ||
Calling this API is now easy and has builtin autocomplete features : | ||
```typescript | ||
// typed auto-complete path auto-complete params | ||
@@ -76,6 +82,12 @@ // ▼ ▼ ▼ | ||
console.log(user); | ||
// Output: { id: 7, name: 'Kurtis Weissnat' } | ||
``` | ||
It should output | ||
```js | ||
{ id: 7, name: 'Kurtis Weissnat' } | ||
``` | ||
## Use token provider plugin | ||
Zodios comes with a plugin to inject and renew your tokens : | ||
@@ -129,3 +141,5 @@ ```typescript | ||
It's a thin wrapper around React-Query but with zodios auto completion. | ||
Zodios query hook also returns an invalidation helper to allow you to reset react query cache easily | ||
```typescript | ||
@@ -170,3 +184,2 @@ import { QueryClient, QueryClientProvider } from 'react-query'; | ||
const queryClient = new QueryClient(); | ||
const zodios = new Zodios(baseUrl, api); | ||
@@ -176,4 +189,11 @@ const zodiosHooks = new ZodiosHooks("jsonplaceholder", zodios); | ||
const Users = () => { | ||
const { data: users, isLoading, error } = zodiosHooks.useQuery("/users"); | ||
const { mutate } = zodiosHooks.useMutation("post", "/users"); | ||
const { | ||
data: users, | ||
isLoading, | ||
error, | ||
invalidate: invalidateUsers, | ||
} = zodiosHooks.useQuery("/users"); | ||
const { mutate } = zodiosHooks.useMutation("post", "/users", { | ||
onSuccess: () => invalidateUsers(), // zodios also provides invalidation helpers | ||
}); | ||
@@ -199,2 +219,5 @@ return ( | ||
// on another file | ||
const queryClient = new QueryClient(); | ||
export const App = () => { | ||
@@ -201,0 +224,0 @@ return ( |
Sorry, the diff of this file is too big to display
993925
15917
224