Skip to content

Instantly share code, notes, and snippets.

View david-arteaga's full-sized avatar

David Arteaga david-arteaga

View GitHub Profile
@david-arteaga
david-arteaga / useLogKeyDifferences.ts
Created April 13, 2022 15:20
[useLogKeyDifferences] #react #debugging
import { useRef } from 'react';
export default function useLogKeyDifferences<Type>(object: Type) {
const objectRef = useRef<undefined | Type>(undefined);
const previousObject = objectRef.current;
objectRef.current = object;
const differentKeys = new Set<keyof Type>();
(Object.keys(object) as (keyof Type)[]).forEach((key) => {
const prev = previousObject?.[key];
const current = object[key];
@david-arteaga
david-arteaga / file.md
Created August 30, 2021 15:25
[Enable vim copy and paste in macOS] #vim #macos #

Try:

:set clipboard=unnamed

or

:set clipboard=unnamedplus


@david-arteaga
david-arteaga / rerender.js
Created November 27, 2020 15:41
Re-render Monaco editor completions widget
/**
* This is useful when you have both sync and async completions and don't want to have to wait for the async completions to resolve
* to show the already available sync completions.
*/
function rerenderCompletions() {
editor.trigger('editor', 'hideSuggestWidget', null);
editor.trigger('source', 'editor.action.triggerSuggest', null);
}
@david-arteaga
david-arteaga / useSpreadState.ts
Created September 20, 2020 04:32
[useSpreadState] #react #typescript #hooks
import React from 'react';
import { useState, useCallback } from 'react';
export type SetSpreadStateFn<T> = (
s: Partial<T> | ((ns: T) => Partial<T>),
) => void;
export type SpreadStateReturnType<T> = [T, SetSpreadStateFn<T>];
export default function useSpreadState<State>(
@david-arteaga
david-arteaga / useMemoedObjectLiteral.tsx
Created September 19, 2020 15:53
[useMemoedObjectLiteral] #react #typescript #memoed
import { useMemo } from 'react';
/**
* Memoize an object based on it's keys and values. MAKE SURE the object always has the same
* keys and values
* @param object An object that will always have the same number of properties
*/
export default function useMemoedObjectLiteral<T>(object: T): T {
return useMemo(() => object, Object.values(object));
}
@david-arteaga
david-arteaga / cloudSettings
Last active September 16, 2020 15:22
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-16T15:22:47.632Z","extensionVersion":"v3.4.3"}
@david-arteaga
david-arteaga / TextInput.tsx
Last active August 29, 2020 17:41
[React Native Improved TextInput] #react-native #performance #TextInput
import React, {useCallback, useRef, useLayoutEffect} from 'react';
import {TextInput as RNTextInput, TextInputProps} from 'react-native';
const TextInput = React.forwardRef<RNTextInput, TextInputProps>(
function TextInput(
{value, onChangeText: _onChangeText, defaultValue: _defaultValue, ...props},
forwardRef,
) {
const ref = useRef<RNTextInput | null>(null);
@david-arteaga
david-arteaga / Screen.tsx
Last active September 5, 2024 20:44
[React Native SafeAreaView, KeyboardAvoidingView, ScrollView] The best way to handle safe areas and keyboard in a scroll view #react-native #SafeAreaView #ScrollView #KeyboardAvoidingView
import React from 'react';
import {
SafeAreaView,
StyleSheet,
KeyboardAvoidingView,
ScrollView,
Platform,
} from 'react-native';
export default function Screen() {
@david-arteaga
david-arteaga / typescriptreact.json
Created January 11, 2020 21:34
[Typescript React VS Code snippet]
{
// Place your snippets for typescriptreact here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@david-arteaga
david-arteaga / typescript.json
Created January 11, 2020 21:34
[Typescript VS Code snippets]
{
// Place your snippets for typescript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",