Skip to content

Instantly share code, notes, and snippets.

import React, { useRef, useEffect } from 'react';
function RefComponent() {
const inputRef = useRef(null);
useEffect(() => {
inputRef.current.focus();
}, []);
return (
@iseekTo
iseekTo / Ether.js
Created March 8, 2023 08:34
etherjs point
## search transaction whether is completed
https://docs.ethers.org/v5/api/providers/provider/#Provider-getTransactionReceipt
@iseekTo
iseekTo / MetaMask & Contract Error Collections
Created March 8, 2023 08:32
MetaMask & Contract Error Collections
https://github.com/enzoferey/ethers-error-parser
https://github.com/MetaMask/eth-rpc-errors
@iseekTo
iseekTo / counterContext.ts
Last active January 29, 2022 09:23
Create core context file
import { createContext } from "react";
// Using an enumeration instead of a regular string
// can be very effective in letting us know who used it and what they did
export enum CounterActionEnum {
INCREMENT = "INCREMENT",
DECREMENT = "DECREMENT",
}
export type ActionType = {
@iseekTo
iseekTo / OmitPartial.ts
Last active November 4, 2021 12:11
Combine the original type and the optional type.
// First
type OmitPartial<T, K extends keyof T> = Omit<T, K> & {
[Key in K]?: T[Key]
}
// Also
type OmitPartial<T, K extends keyof T> = Omit<T, K> & Partial<Record<K, T[K]>>
@iseekTo
iseekTo / Unexposed props.tsx
Created November 1, 2021 10:18
Get unexposed props from external library
// Suppose there are no props for the Link component
import { Link } from 'react-router-dom'
// Use `React.ComponentProps` to get its props
type LinkProps = React.ComponentProps<typeof Link>
const ExtraLink: React.FC<LinkProps> = ({ to, ...props }) => (
// To use
<Link to={to || 'login'} {...props} />
@iseekTo
iseekTo / react.tsx
Last active November 1, 2021 10:13
useRef type
import type { FC } from 'react';
import { useEffect } from 'react';
const Example: FC = () => {
useEffect(() => {
let timeoutId: ReturnType<typeof setTimeout> | null = null;
return () => {
if (timeoutId) {