This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react'; | |
| interface TabItem { | |
| id: string; | |
| title: React.ReactNode; | |
| body: React.ReactNode; | |
| } | |
| interface TabPanelProps { | |
| items: TabItem[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useSyncExternalStore } from "react"; | |
| function subscribe(onStoreChange: () => void) { | |
| console.log("called"); | |
| window.addEventListener("resize", onStoreChange); | |
| return () => window.removeEventListener("resize", onStoreChange); | |
| } | |
| function getServerSnapshot() { | |
| return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { renderHook } from '@testing-library/react'; | |
| import { act } from 'react-dom/test-utils'; | |
| import { useLocalStorage } from './useLocalStorage'; | |
| describe('useLocalStorage', () => { | |
| const key = 'test-key'; | |
| const value = 'test-value'; | |
| beforeEach(() => { | |
| jest.clearAllMocks(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Renders supplied properties of an object required | |
| */ | |
| type Requirer <T, K extends keyof T> = T & { [P in K]-?: T[P] } | |
| interface Foo { | |
| opt?: string; | |
| } | |
| type ReqFoo = Requirer<Foo, 'opt'> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare const __brand: unique symbol; | |
| type Branded<Type, Brand> = Type & { | |
| readonly [__brand]: Brand; | |
| }; | |
| type RouteName = `/${string}`; | |
| type BrandedRouteName = Branded<RouteName, 'RouteName'>; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const filterByPropertyKey = <TObj extends Object,>( | |
| collection: Readonly<TObj[]>, | |
| filters: Record<string, unknown>, | |
| ) => { | |
| if (Object.keys(filters).length === 0) { | |
| return collection; | |
| } | |
| return collection.filter((item) => { | |
| let include = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface PromiseRes <TObj>{ | |
| fulfilled: TObj[]; | |
| rejects: PromiseRejectedResult[]; | |
| } | |
| /** | |
| * Given an array of promises it will wait for every item to be resolved or rejected | |
| * and returns the fulfilled and rejected objects in two separate arrays | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * Selects elements from target object by provided keys | |
| */ | |
| export const pick = <T extends object, K extends keyof T = keyof T>( | |
| object: T, | |
| keys: K[] | |
| ): Pick<T, K> => { | |
| let output: any = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Groups elements in an array by a given key (if that key exists within each | |
| * iteratee) | |
| * | |
| * *Optional: you can provide a getter function to access a value within each | |
| * item of the array* | |
| */ | |
| const groupBy = <T extends Record<string, any>, U = T[keyof T]>( | |
| key: keyof T, | |
| array: T[], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :root { | |
| --prefers-reduced-motion: 1; | |
| @media (prefers-reduced-motion) { | |
| --prefers-reduced-motion: 0; | |
| } | |
| } | |
| @function animationMs($speed) { | |
| @return calc(#{$speed} * var(--prefers-reduced-motion))ms; |
NewerOlder