English | 简体中文
Hooks
for frontend and backendWebpack / Vite
based projectsBackend(Midway Hooks) | Frontend(React) |
---|---|
```tsx
// src/api/index.ts
import {
Api,
Get,
Post,
Validate,
Query,
useContext,
} from '@midwayjs/hooks';
import { z } from 'zod';
import db from './database';
export const getArticles = Api(
Get(),
Query<{ page: string; per_page: string }>(),
async () => {
const ctx = useContext();
const articles = await db.articles.find({
page: ctx.query.page,
per_page: ctx.query.per_page,
});
return articles;
}
);
const ArticleSchema = z.object({
title: z.string().min(3).max(16),
content: z.string().min(1),
});
export const createArticle = Api(
Post(),
Validate(ArticleSchema),
async (article: z.infer |
```ts
// src/pages/articles.tsx
import { getArticles } from '../api';
import { useRequest } from 'ahooks';
import ArticleList from './components/ArticleList';
export default () => {
const { data } = useRequest(() =>
getArticles({
query: {
page: '1',
per_page: '10',
},
})
);
return |
Midway Hooks currently provide the following templates:
You can create applications quickly with templates:
npx degit https://github.com/midwayjs/hooks/examples/<name>
For example, create a fullstack application with react:
npx degit https://github.com/midwayjs/hooks/examples/react
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
We use pnpm to manage the project.
$ pnpm install
$ pnpm build
$ pnpm watch
$ pnpm test
Thanks goes to these wonderful people (emoji key):
Lxxyx 💻 🖋 🤔 👀 ⚠️ 📖 |
Gao Yang 💻 🖋 ⚠️ 📖 |
狼叔 📖 |
Eward 💻 |
Linbudu 📖 |
rojer 💻 |
Thetiso 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!