Skip to content

Instantly share code, notes, and snippets.

View saadriazkhan's full-sized avatar

Muhammad Saad Riaz Khan saadriazkhan

  • Berlin, Germany
View GitHub Profile
@saadriazkhan
saadriazkhan / change-query-parameters.tsx
Last active December 7, 2021 01:33
React useSearchParams hook in v6 to update query parameters
import { ChangeEvent } from 'react';
import { useSearchParams } from 'react-router-dom';
// Temporary key of my query parameter
const MY_QUERY_PARAMETER: string = 'myQueryParameter';
export const UpdateQueryParameters = (props: any) => {
// Hook which returns a tuple. First element is the current URLSearchParams object and second element is the function to take in the new URLSearchParams object alongside a configuration object to either replace the query parameters or not alongside state.
const [currentQueryParameters, setSearchParams] = useSearchParams();
const newQueryParameters : URLSearchParams = new URLSearchParams();
@saadriazkhan
saadriazkhan / refreshtoken-graphql.interceptor.tsx
Last active April 9, 2021 21:43
Apolloclient refresh token implementation with RxJS in React
import { from, of, Observable, forkJoin } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
// I have made a token service. which exposes
// setAccessToken, setRefreshToken, getRefreshToken, getAccessToken methods interacting with browser localStorage. Feel free to change as per your application architecture
import { tokenService, userService } from './tokenService';
// high level flag to prevent getting into refreshing mode again.
let IS_REFRESHING: boolean = false;
export const refreshTokenInterceptorCustomFetch = (uri: RequestInfo, intitalOptions: RequestInit): Promise<Response> =>