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, { useRef, useEffect } from 'react'; | |
| function RefComponent() { | |
| const inputRef = useRef(null); | |
| useEffect(() => { | |
| inputRef.current.focus(); | |
| }, []); | |
| return ( |
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
| ## search transaction whether is completed | |
| https://docs.ethers.org/v5/api/providers/provider/#Provider-getTransactionReceipt |
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
| https://github.com/enzoferey/ethers-error-parser | |
| https://github.com/MetaMask/eth-rpc-errors |
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 { 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 = { |
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
| // 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]>> |
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
| // 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} /> |
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 type { FC } from 'react'; | |
| import { useEffect } from 'react'; | |
| const Example: FC = () => { | |
| useEffect(() => { | |
| let timeoutId: ReturnType<typeof setTimeout> | null = null; | |
| return () => { | |
| if (timeoutId) { |