Skip to content

Commit

Permalink
react hook form server action
Browse files Browse the repository at this point in the history
  • Loading branch information
kdh379 committed May 9, 2024
1 parent e40de69 commit 1e02563
Show file tree
Hide file tree
Showing 28 changed files with 1,649 additions and 288 deletions.
51 changes: 50 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
{
"extends": "next/core-web-vitals"
"extends": [
"next/core-web-vitals",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:tailwindcss/recommended"
],
"plugins": [
"simple-import-sort",
"unused-imports",
"tailwindcss"
],
"settings": {
"tailwindcss": {
"callees": ["cn"],
"config": "tailwind.config.js"
},
"next": {
"rootDir": ["./src/"]
}
},
"rules": {
// Code style
"indent": ["error", 2],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "never",
"exports": "never",
"functions": "never"
}],
"comma-spacing": ["error", { "before": false, "after": true }],
"no-console": "warn",
"tailwindcss/no-custom-classname": "off",

// import / export
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"unused-imports/no-unused-imports-ts": ["error"],

// React
"react/react-in-jsx-scope": 0,
"react/jsx-first-prop-new-line": "error",
"react/self-closing-comp": ["error", {
"component": true,
"html": true
}],
"react/no-unknown-property": "error"
}
}
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// tailwind @import
"css.lint.unknownAtRules": "ignore",
// eslint
"eslint.format.enable": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
// use ts path alias
"typescript.preferences.importModuleSpecifier": "non-relative",
// tailwindcss + cva
"tailwindCSS.experimental.classRegex": [
[
"cva\\(([^)]*)\\)",
"[\"'`]([^\"'`]*).*?[\"'`]"
],
[
"cx\\(([^)]*)\\)",
"(?:'|\"|`)([^']*)(?:'|\"|`)"
]
],
}
42 changes: 16 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# React Hook Form with Server Actions

## Getting Started
I created custom hooks to handle server actions with React Hook Form.
It's declarative way to handle form validation and submission, success and error cases.

First, run the development server:
1. keep **progressive enhancement** working
2. handle actions and form state via `useFormState` and `useFormStatus`.

## Installation

```bash
npm run dev
# or
yarn dev
# or
npm install global pnpm
pnpm install
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Main Source Code

## Deploy on Vercel
- [useFormAction](./src/hooks/useFormAction.js)
- [action.d.ts](./src/types/action.d.ts)
- If you want to add your own handler, check this file.

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
## Sample

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
- [client side form](./src/app/client-side-form.tsx)
- [actions](./src/actions.ts)
17 changes: 17 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/app/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@
"lint": "next lint"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.378.0",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18",
"next": "14.2.3"
"react-hook-form": "^7.51.4",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8.57.0",
"eslint-config-next": "14.2.3",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-tailwindcss": "^3.15.1",
"eslint-plugin-unused-imports": "^3.2.0",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"eslint": "^8",
"eslint-config-next": "14.2.3"
"typescript": "^5"
}
}
Loading

0 comments on commit 1e02563

Please sign in to comment.