Skip to content

Instantly share code, notes, and snippets.

View KajSzy's full-sized avatar

Kajetan Szymczak KajSzy

  • Warsaw
  • 12:09 (UTC -12:00)
View GitHub Profile
import { useState } from 'react';
export const useBoolean = (defaultValue = false) => {
const [value, setValue] = useState(defaultValue);
const setFalse = () => setValue(false);
const setTrue = () => setValue(true);
const toggle = (flag?: boolean) => setValue((prev) => flag ?? !prev);
return [value, { setFalse, setTrue, toggle }] as const;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const connection = window.__REDUX_DEVTOOLS_EXTENSION__?.connect({
// https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#options
name: 'Breadcrumb',
trace: true,
});
const breadcrumbSubject = new BehaviorSubject<BreadcrumbState>([]);
@KajSzy
KajSzy / Loader.tsx
Last active August 14, 2021 11:09
Animated text loader
import * as React from 'react'
type LoaderProps = {
label?: string
animationIteration?: number
animationDelay?: number
stayOnLabelFor?: number
loopAnimation?: boolean
}
@KajSzy
KajSzy / redisConnector.ts
Last active August 4, 2021 07:03
Wrapper for redis for node js applications
import { Callback, ClientOpts, createClient, RedisClient } from "redis";
class RedisConnector {
private client: RedisClient;
private expirationTime = 3600;
static instance: RedisConnector = new RedisConnector();
private constructor(useTLS = process.env.REDIS_TLS) {
const options: ClientOpts = {
host: process.env.REDIS_URL,
@KajSzy
KajSzy / useBreakpoints.ts
Last active January 11, 2021 07:52
Example of using Template Literal Types introduced in Typescript 4.1
import { useMediaQuery, useTheme } from '@material-ui/core';
type Devices = 'mobile' | 'tablet' | 'desktop';
type DeviceKey = `is${Capitalize<Devices>}`;
export const useBreakpoints = (): Record<DeviceKey, boolean> => {
const theme = useTheme();
return {
isMobile: useMediaQuery(theme.breakpoints.down('sm')),