Sıkça kullandığım, tekrar kullanılabilir kod parçacıkları.
CSS Reset
Minimal ve modern bir CSS reset şablonu.
1*,
2*::before,
3*::after {
4 box-sizing: border-box;
5 margin: 0;
6 padding: 0;
7}
8
9html {
10 -webkit-text-size-adjust: 100%;
11 -moz-tab-size: 4;
12 tab-size: 4;
13}
14
15body {
16 line-height: 1.5;
17 -webkit-font-smoothing: antialiased;
18}
19
20img, picture, video, canvas, svg {
21 display: block;
22 max-width: 100%;
23}
24
25input, button, textarea, select {
26 font: inherit;
27}useLocalStorage Hook
localStorage ile senkronize çalışan bir React hook'u.
1import { useState, useEffect } from "react";
2
3export function useLocalStorage<T>(key: string, initialValue: T) {
4 const [value, setValue] = useState<T>(() => {
5 if (typeof window === "undefined") return initialValue;
6 const stored = localStorage.getItem(key);
7 return stored ? JSON.parse(stored) : initialValue;
8 });
9
10 useEffect(() => {
11 localStorage.setItem(key, JSON.stringify(value));
12 }, [key, value]);
13
14 return [value, setValue] as const;
15}