Skip to content

Instantly share code, notes, and snippets.

View sarakusha's full-sized avatar

Andrei Sarakeev sarakusha

  • Nata Info OOO
  • Yoshkar-Ola, Russia
View GitHub Profile
@sarakusha
sarakusha / getStateAsync.ts
Last active March 10, 2022 07:12
Can be used in custom hooks and allows you to get the current state (states) from the `useState` hook without adding a dependency.
import { Dispatch, SetStateAction } from 'react';
type Setter<S> = Dispatch<SetStateAction<S>>;
/**
* Can be used in custom hooks and allows you to get the current state from the `useState` hook
* without adding a dependency.
* @param setter
* @example
* ```
@sarakusha
sarakusha / createDebouncedAsyncThunk.ts
Last active December 30, 2023 16:26
A debounced analogue of `createAsyncThunk` from `@reduxjs/toolkit`
import { createAsyncThunk, AsyncThunkPayloadCreator, AsyncThunk } from '@reduxjs/toolkit';
type DebounceSettings = {
/**
* The maximum time `payloadCreator` is allowed to be delayed before
* it's invoked.
* @defaultValue `0`
*/
maxWait?: number;
/**