This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) | |
pragma solidity ^0.8.0; | |
import "../utils/Context.sol"; | |
/** | |
* @dev Contract module which provides a basic access control mechanism, where | |
* there is an account (an owner) that can be granted exclusive access to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// type Todo = {id: string, title: string} | |
// MyPick<Todo, 'title'> | |
type MyPick<T, K extends keyof T> = { | |
[S in K]: T[S] | |
} | |
// type R = MyReadonly<{id: string}> | |
type MyReadonly<T> = { | |
readonly [S in keyof T]: T[S] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react" | |
/** | |
* Runs a timeout after delay ms. | |
* | |
* @param callback function to execute | |
* @param delay delay time in ms | |
* | |
* Usage: | |
useTimeout( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react" | |
type HookProps = { | |
key?: string | |
keyCode: number | |
onKeyPress?: () => void | |
enabled?: boolean | |
} | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useCallback, useMemo } from "react" | |
import LanguageKeysDe from "./de" | |
import LanguageKeys, { LangProps } from "./en" | |
/** | |
Full example here: | |
https://codesandbox.io/s/simple-react-typescript-i18n-w0ut6 | |
**/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react" | |
/** | |
Usage: | |
// Ref for the element that we want to detect whether on screen | |
const ref = useRef<HTMLDivElement>(null) | |
// Call the hook passing in ref and root margin | |
// In this case it would only be considered onScreen if more ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react" | |
function useInterval(callback: () => void, delay: number) { | |
const savedCallback = useRef<() => void | undefined>() | |
useEffect(() => { | |
savedCallback.current = callback | |
}) | |
useEffect(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
To check the order of elements you can use the underlying dom testing lib to search in specific elements. The following example gets all table rows and checks then for specific text in each row. | |
**/ | |
import { getByText as domGetByText } from "@testing-library/react" | |
describe("StockTable", () => { | |
it("renders countries in correct order by country code", async () => { | |
const { getAllByTestId } = render(<StockTable offers={offers} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const food = ['apple', 'banana', 'cookie'] as const | |
// 'apple', 'banana', 'cookie' | |
type Food = typeof food[number] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a bookmark and use this code as the URL, you can now toggle the css on/off | |
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3 | |
javascript: (function() { | |
var elements = document.body.getElementsByTagName('*'); | |
var items = []; | |
for (var i = 0; i < elements.length; i++) { | |
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) { | |
items.push(elements[i]); | |
} | |
} |
NewerOlder