@hulanbv/nest-utilities-client-state
Advanced tools
Comparing version 0.5.1 to 0.5.3
{ | ||
"name": "@hulanbv/nest-utilities-client-state", | ||
"version": "0.5.1", | ||
"version": "0.5.3", | ||
"description": "React hooks for state management when using nest-utilities-client and a nest-utilities based API.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -467,2 +467,28 @@ # nest-utilities-client-state | ||
Note that when invoking `useRequest`, no immediate fetch takes place. The `immediateFetch` option is _ignored_, so you will have to manually invoke the created state's `call` method if you want to immediately fetch on creation. | ||
```typescript | ||
function useSomeData() { | ||
const { data, call } = useRequest(service, 'query', 'GET'); | ||
// manual immediate fetch | ||
useEffect(() => void call(), []); | ||
return data | ||
} | ||
// or, a more common scenario with an optional query parameter | ||
function useSomeData(id?: string) { | ||
const { data, call } = useRequest(service, id, 'GET'); | ||
// manual immediate fetch, but only if `id` is defined | ||
useEffect(() => { | ||
if (id) call(); | ||
}, [id]); | ||
return data | ||
} | ||
``` | ||
### `interface IRequestState` | ||
@@ -469,0 +495,0 @@ |
88357
51
559