Skip to content

Instantly share code, notes, and snippets.

View latobibor's full-sized avatar
🎯
Focusing

András Tóth latobibor

🎯
Focusing
  • Budapest
View GitHub Profile
@latobibor
latobibor / use-abortable-fetch.ts
Last active June 28, 2024 00:25
useAbortableFetch
import { useRef } from 'react';
// wanna send a ton of requests but only needing the last one?
// note: on the backend even aborted requests are going to use resources
export function useAbortableFetch() {
const controllerRef = useRef<AbortController | null>(null);
async function fetchThatAbortsPreviousCall(
input: string | URL | Request,
options?: RequestInit,
@latobibor
latobibor / use-dependency-spy.ts
Last active January 20, 2024 02:07
React dependency spy
/**
* Ever wondered what triggered a rerendering in React?
* Who was the killer? Which dependency got updated?
* This is a very stupid little code that can help you debug the issue.
*/
import { useRef } from 'react';
type DependenciesObject = {
[dependencyName: string]: any;