Skip to content

Instantly share code, notes, and snippets.

View KacperKozak's full-sized avatar

Kacper Kozak KacperKozak

View GitHub Profile
@KacperKozak
KacperKozak / Tab.tsx
Created April 3, 2023 11:22
React tabs
import React, { ReactNode } from 'react'
export interface TabProps {
name: string
isActive?: boolean
children: ReactNode
}
export const Tab = ({ children }: TabProps) => <>{children}</>
@KacperKozak
KacperKozak / useObject.ts
Created September 5, 2023 13:15
`useObject` hook
import { useReducer } from 'react';
type Reducer<T> = (state: T, update: Partial<T>) => T;
export const useObject = <T>(initial: T) => {
return useReducer<Reducer<T>>((state, update) => ({ ...state, ...update }), initial);
};
// ludzie-iza.json
{
"name": "Izabela",
"age": 25,
"city": "Warsaw",
"description": {
"pl": "Jestem programistką",
"en": "I'm a programmer",
"de": "Ich bin Programmiererin"
}
import { useMemo } from 'react';
/**
* A hook that returns a memoized version of the given object or array.
* **Important!** Use only if the object structure or array length is not changing!
*
* @example
* ```ts
* const api = useStructMemo({ query, setQuery, count });
* ```