Skip to content

Instantly share code, notes, and snippets.

View KirillTregubov's full-sized avatar
:shipit:
Working to improve every day!

Kirill Tregubov KirillTregubov

:shipit:
Working to improve every day!
View GitHub Profile
{
"arrowParens": "always",
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"plugins": [
"prettier-plugin-tailwindcss"
]
}
app.post<{
Body: {
userId: string
}
// More keys: https://fastify.dev/docs/latest/Reference/TypeScript/#using-generics (3rd step)
}>(
'/my-endpoint',
async ({ body }, reply) {
console.log(body) // <- is of correct type
}
import { createContext, useContext, useReducer } from 'react'
type State = {
isLoading: boolean
isSignout: boolean
userToken: string | null
}
type Action =
| { type: 'LOADED' }
@KirillTregubov
KirillTregubov / usePreserveScroll.tsx
Created July 16, 2022 15:21 — forked from Jak-Ch-ll/usePreserveScroll.tsx
Next.js - Preserve Scroll History
import { useRouter } from "next/router"
import { useEffect, useRef } from "react"
export const usePreserveScroll = () => {
const router = useRouter()
const scrollPositions = useRef<{ [url: string]: number }>({})
const isBack = useRef(false)
useEffect(() => {
@KirillTregubov
KirillTregubov / component.tsx
Last active July 12, 2022 21:00
Type-safe React functional component scaffolding
const Component: React.FC = () => {
return <></>
}