Hooks
"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
Install / Use
/learn @midwayjs/HooksREADME
English | 简体中文
✨ Features
- ☁️ Maximize productivity and developer experience, support fullstack development & API service
- ⚡️ Fullstack kit that supports React/Vue/Svelte... and more frameworks
- 🌈 "Zero" Api data layer, import functions from the backend to call the API directly, without the ajax glue layer
- ⛑️ Type safe, use the identical type definition from frontend to backend, detect errors in advance
- 🌍 Functional programming, using
Hooksfor frontend and backend - ⚙️ Support for
Webpack / Vitebased projects - ✈️ Deploy to Server or Serverless
- 🛡 Based on Midway, a powerful Node.js framework that supports enterprise-level application development
🔨 Preview
<table> <tr> <th style="text-align: center;"> Backend(Midway Hooks) </th> <th style="text-align: center;"> Frontend(React) </th> </tr> <tr> <td> <sub> <!-- prettier-ignore -->// 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<typeof ArticleSchema>) => {
const newArticle = await db.articles.create(article);
return {
id: newArticle.id,
};
}
);
</sub>
</td>
<td>
<sub>
// 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 <ArticleList articles={data} />;
};
// src/pages/new.tsx
import { createArticle } from '../api';
import Editor from './components/Editor';
import { useState } from 'react';
export default () => {
const [loading, setLoading] = useState(false);
const handleSubmit = async (article) => {
setLoading(true);
const { id } = await createArticle(article);
setLoading(false);
location.href = `/articles/${id}`;
};
return <Editor loading={loading} onSubmit={handleSubmit} />;
};
</sub>
</td>
</tr>
</table>
🧩 Templates
Midway Hooks currently provide the following templates:
- Fullstack
- Serverless
- Api Server
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
Contribute
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
We use pnpm to manage the project.
- install dependencies
$ pnpm install
- build
$ pnpm build
- watch
$ pnpm watch
- test
$ pnpm test
Contributors ✨
Thanks goes to these wonderful people (emoji key):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center"><a href="https://blog.lxxyx.cn/"><img src="https://avatars.githubusercontent.com/u/13161470?v=4?s=100" width="100px;" alt="Lxxyx"/><br /><sub><b>Lxxyx</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=Lxxyx" title="Code">💻</a> <a href="#content-Lxxyx" title="Content">🖋</a> <a href="#ideas-Lxxyx" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/midwayjs/hooks/pulls?q=is%3Apr+reviewed-by%3ALxxyx" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/midwayjs/hooks/commits?author=Lxxyx" title="Tests">⚠️</a> <a href="https://github.com/midwayjs/hooks/commits?author=Lxxyx" title="Documentation">📖</a></td> <td align="center"><a href="https://iam.gy/"><img src="https://avatars.githubusercontent.com/u/14832743?v=4?s=100" width="100px;" alt="Gao Yang"/><br /><sub><b>Gao Yang</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=echosoar" title="Code">💻</a> <a href="#content-echosoar" title="Content">🖋</a> <a href="https://github.com/midwayjs/hooks/commits?author=echosoar" title="Tests">⚠️</a> <a href="https://github.com/midwayjs/hooks/commits?author=echosoar" title="Documentation">📖</a></td> <td align="center"><a href="http://i5ting.com/"><img src="https://avatars.githubusercontent.com/u/3118295?v=4?s=100" width="100px;" alt="狼叔"/><br /><sub><b>狼叔</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=i5ting" title="Documentation">📖</a></td> <td align="center"><a href="https://www.yuque.com/eward/blog"><img src="https://avatars.githubusercontent.com/u/452899?v=4?s=100" width="100px;" alt="Eward"/><br /><sub><b>Eward</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=shepherdwind" title="Code">💻</a></td> <td align="center"><a href="https://linbudu.top/"><img src="https://avatars.githubusercontent.com/u/48507806?v=4?s=100" width="100px;" alt="Linbudu"/><br /><sub><b>Linbudu</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=linbudu599" title="Documentation">📖</a></td> <td align="center"><a href="https://github.com/rojer95"><img src="https://avatars.githubusercontent.com/u/20662049?v=4?s=100" width="100px;" alt="rojer"/><br /><sub><b>rojer</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=rojer95" title="Code">💻</a></td> <td align="center"><a href="https://github.com/Thetiso"><img src="https://avatars.githubusercontent.com/u/8968567?v=4?s=100" width="100px;" alt="Thetiso"/><br /><sub><b>Thetiso</b></sub></a><br /><a href="https://github.com/midwayjs/hooks/commits?author=Thetiso" title="Documentation">📖</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->This project follows the all-contributors specification. Contributions of any kind welcome!
About
License
Related Skills
bluebubbles
344.1kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
slack
344.1kUse when you need to control Slack from OpenClaw via the slack tool, including reacting to messages or pinning/unpinning items in Slack channels or DMs.
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
