Skip to content

Instantly share code, notes, and snippets.

View SitaGomes's full-sized avatar
🔥
Copying code

Arthur Sita Gomes SitaGomes

🔥
Copying code
View GitHub Profile
@SitaGomes
SitaGomes / useGetViewPort
Created January 10, 2024 16:53
A hook that returns the current view port of the page
export const useGetViewPort = () => {
const [width, setWidth] = useState(window.innerWidth);
useEffect(() => {
const handleWindowResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleWindowResize);
return () => window.removeEventListener("resize", handleWindowResize);
}, []);
@SitaGomes
SitaGomes / useLocalStorage
Last active March 23, 2024 02:11
useLocalStorage
import { useState, useEffect, Dispatch, SetStateAction } from "react";
type Response<T> = [
T, //? What's inside the "state" Ex: string, boolean...
Dispatch<SetStateAction<T>> //? type of "setState"
]
//? "useLocalState<T>" accepts a type unknown
export function useLocalState<T>(key: string, initialState: T): Response<T> {
@SitaGomes
SitaGomes / gist:adbb6d4d805063a65aec0d7e0728d6cf
Created March 8, 2023 20:06
How to write a good pull request description
## What?
Explain the changes you’ve made. It doesn’t need to be fancy and you don’t have to get to technical, yet. Just explicit prose on your net change will typically suffice. At a high level, this is where you let the reviewer know the overall effect of the PR. Reference a ticket in your issue tracker if appropriate, but by all means, don’t just reference the ticket. It’s important to explain what the change is and then and only then reference the ticket. It’s a much better experience for the reviewer if they’re able to spend more time reviewing code and less time studying specification that may not even be applicable on the code level.
## Why?
The “why” is sometimes more important than the “what” of a code change, but we tend to put it after the “what” since we aren’t evaluating theory, we’re evaluating tangible code changes.
The “why” tells us what business or engineering goal this change achieves. It’s the reason we get paid as developers. The “why” is a chance to explain both the engineering goal, bu