Skip to content

Instantly share code, notes, and snippets.

View Hidekih's full-sized avatar

Alexandre Hideki Siroma Hidekih

View GitHub Profile
/// <summary>
/// A DelegatingHandler that retries the request if it fails due to an expired token.
/// </summary>
sealed class RetryHandler : DelegatingHandler
{
private const int _maxRetries = 3;
private string? _accessToken = null;
public RetryHandler(
HttpMessageHandler innerHandler
@Hidekih
Hidekih / useFetch.ts
Created February 4, 2023 23:10
A react hook to handle fetch with Axios.
import { AxiosError, AxiosResponse } from "axios";
import { useCallback, useEffect, useState } from "react";
interface UseFetchProps<DataType = object> {
/**
* Default is `true`
*/
initialFetch?: boolean;
fetch: () => Promise<AxiosResponse<DataType, any>>;
errorCallback?: () => void;