A function that displays the content of a variable or function return on the console without compromising the flow.
Javascript:
function tap(x, fn) {
console.log(fn(x));
return x;
}
export const useDragToScroll = (ref: Ref<HTMLElement | null>) => {
const position = {
left: 0,
x: 0
}
const mouseDown = (event: MouseEvent) => {
if (ref.value === null) return
position.x = event.clientX
import React from "react";
function useLocalStorage<T>(key: string) {
const [data, setData] = React.useState<T | null>(() => {
const backup = localStorage.getItem(key);
return typeof backup === "string" ? (JSON.parse(backup) as T) : backup;
});
function updateState() {
import { useEffect, useRef, useState } from 'react' | |
const countElementLines = (target: HTMLElement) => { | |
const style = window.getComputedStyle(target, null) | |
const fontSize = parseInt(style.getPropertyValue('font-size')) | |
let height = parseInt(style.getPropertyValue('height')) | |
const boxSizing = style.getPropertyValue('box-sizing') | |
if (boxSizing === 'border-box') { |
const memoryCache = new Map<string, any>() | |
/** | |
* `resetCachedFetch` is a function that clears the cachedFetch cache. | |
* It does not take any parameters and does not return any value. | |
*/ | |
export const resetCachedFetch = () => memoryCache.clear() | |
/** | |
* `cachedFetch` is a generic function that performs a fetch operation and caches the result. |
export const getCurrentTime = () => { | |
return 1000 * Math.floor(Date.now() / 1000 + 0.1) | |
} | |
export const getNextHourTimestamp = () => { | |
const date = new Date(); | |
const currentHours = date.getHours(); | |
date.setHours(currentHours + 1) | |
date.setMinutes(0) |
// Intersect string with {}: | |
export type StateWords = | 'first' | 'second' | 'third' | string & {} | |
// Record<never, never> can also work: | |
export type StateWords = | 'first' | 'second' | 'third' | string & Record<never, never> | |
// These intersections trick TypeScript into thinking that it is a "different" string type that literal string types are not assignable to (and thus the union won't get reduced to only string). |
name: Reusable install deps | |
description: This workflow installs dependencies using PNPM and caches the store directory. It is meant to be used as a reusable workflow. | |
inputs: | |
NODE_VERSION: | |
description: 'The version of Node.js to use' | |
required: true | |
default: '18.x' | |
PNPM_VERSION: | |
description: 'The version of PNPM to use' | |
required: true |
const squareRoot = (n, g = 1, lg) => g === lg ? g : squareRoot(n, (g + (n / g)) / 2, g); |
// App.test.tsx | |
import { describe, it } from "vitest"; | |
import { render, screen } from "@testing-library/react"; | |
import { App } from "./App"; | |
// Comente ou descomente essa linha para ver a diferença entre mockado e não mockado. | |
// vi.mock(import("./useFetch")); | |