swr#SWRHook TypeScript Examples
The following examples show how to use
swr#SWRHook.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useProposal.ts From dxvote with GNU Affero General Public License v3.0 | 6 votes |
formatterMiddleware: Middleware =
(useSWRNext: SWRHook) => (key, fetcher, config) => {
const swr = useSWRNext(key, fetcher, config);
if (swr.data) {
const original = swr.data as any;
const clone: any = Object.assign({}, swr.data);
clone.startTime = original.startTime
? unix(original.startTime.toNumber())
: null;
clone.endTime = original.endTime
? unix(original.endTime.toNumber())
: null;
return { ...swr, data: clone };
}
return swr;
}
Example #2
Source File: logger.ts From dxvote with GNU Affero General Public License v3.0 | 5 votes |
loggerMiddleware: Middleware =
(useSWRNext: SWRHook) => (key, fetcher, config) => {
const extendedFetcher = (...args) => {
console.debug(`[SWR ${key}] Request triggered`);
return fetcher(...args);
};
const response = useSWRNext(key, extendedFetcher, config);
if (response.data) {
console.debug(`[SWR ${key}] Response:`, {
data: response.data,
error: response.error,
});
} else if (response.error) {
console.error(`[SWR ${key}] Response:`, {
data: response.data,
error: response.error,
});
}
return response;
}