function LoginForm() {
const [state, dispatch] = useActionState(loginFormAction, {});
const [_isPending, formAction] = useFormAction(async (formData, form) => {
dispatch({ type: "RESET" });
const errors = validateForm(formData);
if (errors != null) {
dispatch({ type: "SET_INVALID_INPUTS", form, 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
{ | |
"imports": { | |
"#styled-system/*": "./src/styled-system/*/index.js", // remove if you don't use pandacss | |
"#*": { | |
"react-server": [ | |
"./src/*.ts", | |
"./src/*.tsx", | |
"./src/*.server.ts", | |
"./src/*.server.tsx" | |
], |
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 { mock } from "bun:test"; | |
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies"; | |
export function mockNextjsReadonlyCookie() { | |
mock.module("next/headers", () => { | |
const cookieMap = new Map<string, { name: string; value: string }>(); | |
const cookies: ReadonlyRequestCookies = { | |
get: (nameOrCookie: string | { name: string }) => { | |
const name = | |
typeof nameOrCookie === "string" ? nameOrCookie : nameOrCookie.name; |
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 { expect, test } from "vitest"; | |
import { render, screen } from "@testing-library/react"; | |
import { | |
FormDescription, | |
FormError, | |
FormField, | |
FormInput, | |
FormLabel, |
gacm
(Git Add Commit Merge) is a Zsh function that simplifies the process of adding, committing, and optionally pushing Git changes. It combines git add .
, git commit -m
, and (optionally) git push
into a single command, with an additional option for force push.
Add the following function to your ~/.zshrc
file:
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
// you can run this on latest chrome browser and copy the result | |
function arrayBufferToString(buffer) { | |
const bytes = new Uint8Array(buffer) | |
const len = bytes.byteLength | |
// @anonrig: V8 has a limit of 65535 arguments in a function. | |
// For len < 65535, this is faster. | |
// https://github.com/vercel/next.js/pull/56377#pullrequestreview-1656181623 | |
if (len < 65535) { |
React 컴포넌트에서 컨트랙트를 호출하는 다음과 같은 코드가 있다고 가정해봅시다.
function buildCreateTokenTransaction({
name,
symbol,
caipChainID,
creatorAddress,
}: {
caipChainID: CAIPChainID;
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
// copied from https://github.com/facebook/react/blob/8e60bacd08215bd23f0bf05dde407cd133885aa1/packages/react/src/ReactCacheImpl.js#L50 | |
// but no react context | |
const rootCacheNode = new WeakMap<(...args: any[]) => any, CacheNode>(); | |
const UNTERMINATED = 0; | |
const TERMINATED = 1; | |
const ERRORED = 2; | |
type CacheNode = { |
With following context, refactor React components
Minimalistic Deps:
- replace
import * as React from "react"
things toimport { useState, use, ... } from React
only required in the code
Prefer safe prop interface:
- replace
React.*HTMLAttributes
toComponentPropsWithRef<*>
- replace type props to interface props. if
props: A & B
found, convert tointerface Props extends A, B {}
shape
Remove legacy forwardRef API: