midwayjs / hooks

"Zero" Api / Type Safe / Fullstack Kit / Powerful Backend
MIT License
690 stars 63 forks source link
frontend fullstack hooks midway react serverless vite vue

Functional Fullstack Framework

"Zero" Api & Type Safe & Fullstack Kit & Powerful Backend
At Alibaba, 2800+ full-stack applications are developed based on Midway Hooks (2022.01)

English | 简体中文

✨ Features

🔨 Preview

Backend(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) => { const newArticle = await db.articles.create(article); return { id: newArticle.id, }; } ); ``` ```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 ; }; // 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 ; }; ```

🧩 Templates

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

Contribute

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

We use pnpm to manage the project.

$ pnpm install
$ pnpm build
$ pnpm watch
$ pnpm test

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Lxxyx
Lxxyx

💻 🖋 🤔 👀 ⚠️ 📖
Gao Yang
Gao Yang

💻 🖋 ⚠️ 📖
狼叔
狼叔

📖
Eward
Eward

💻
Linbudu
Linbudu

📖
rojer
rojer

💻
Thetiso
Thetiso

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Alibaba Open Source

License

MIT