Skip to content

Instantly share code, notes, and snippets.

View GalindoSVQ's full-sized avatar
🎯
Focusing

Antonio Galindo GalindoSVQ

🎯
Focusing
View GitHub Profile
const response = []
const userObj = {
id: "fd70a8cd-32b5-437a-98b6-2363bda276f1",
name: "Antonio",
lastName: "Galindo",
cardId: 123456789
};
userObj[Symbol.iterator] = function* () {
const values = Object.values(userObj);
const bgColor: Record<string, string> = {
Warning: 'orange',
Error: 'red',
Success: 'green',
}
type msgType = keyof typeof bgColor;
function createPrintLog(type: msgType) {
return function log(str: string) {
type ErrorWithMessage = {
message: string
}
function isErrorWithMessage(error: unknown): error is ErrorWithMessage {
return (
typeof error === 'object' &&
error !== null &&
'message' in error &&
typeof (error as Record<string, unknown>).message === 'string'
import { useEffect } from 'react';
export default function useDocumentTitle(title: string) {
useEffect(() => {
document.title = title;
}, [title]);
}
import { useState } from 'react';
export default function useDefault<T>(initialState: T, defaultState: T) {
const [value, setValue] = useState<T | null | undefined>(initialState);
if (value === null || typeof value === 'undefined') {
return [defaultState, setValue];
}
}
import { useState, useCallback } from 'react';
export default function useToggle(initialValue: boolean = true) {
const [value, setValue] = useState(Boolean(initialValue));
const handleValue = useCallback(
(newValue: any) =>
typeof newValue === 'boolean'
? setValue(newValue)
: setValue((currentValue) => !currentValue),
import * as React from 'react';
export default function usePrevious(newValue: string) {
const [value, setValue] = React.useState<string>(newValue);
const [preValue, setPreValue] = React.useState<string | null>(null);
if (newValue !== value) {
setPreValue(value);
setValue(newValue);
}
import { useSyncExternalStore } from 'react';
const subcribe = (cb: any) => {
addEventListener('languagechange', cb);
return () => removeEventListener('languagechange', cb);
};
const getSnapshot = () => {
return navigator.language;
};
import * as React from 'react';
export default function useFavicon(faviconUrl: string) {
React.useEffect(() => {
let link = document.querySelector(`link[rel~="icon"]`);
if (!link) {
link = document.createElement('link');
link.type = 'image/x-icon';
import * as React from 'react';
function oldSchoolCopy(text) {
const tempTextArea = document.createElement('textarea');
tempTextArea.value = text;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);
}