Skip to content

Commit dedb57f

Browse files
aceHuberthubert
andauthored
feat: react support (#23)
* chore: node version autofix * feat: add react support * chore: lerna publish options fix * chore(release): 😊 publish v0.9.3-alpha.0 * fix: reack hook 在组件外使用问题 * chore(release): 😊 publish v0.9.3-alpha.1 --------- Co-authored-by: hubert <[email protected]>
1 parent b0d2d86 commit dedb57f

29 files changed

+1502
-12
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.20.3

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.9.3-alpha.1](https://github.com/aceHubert/ace-fetch/compare/v0.9.3-alpha.0...v0.9.3-alpha.1) (2025-02-20)
7+
8+
### Bug Fixes
9+
10+
- reack hook 在组件外使用问题 ([00430af](https://github.com/aceHubert/ace-fetch/commit/00430af98440c2c1d08cdbd0da72e749330e6e49))
11+
12+
## [0.9.3-alpha.0](https://github.com/aceHubert/ace-fetch/compare/v0.9.2...v0.9.3-alpha.0) (2025-02-20)
13+
14+
### Features
15+
16+
- add react support ([ec9e444](https://github.com/aceHubert/ace-fetch/commit/ec9e444cd863038517271dfc62b5e964beb03d64))
17+
618
## [0.9.2](https://github.com/aceHubert/ace-fetch/compare/v0.9.1...v0.9.2) (2025-02-20)
719

820
### Performance Improvements

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"message": "chore(release): 😊 publish %s"
2121
}
2222
},
23-
"version": "0.9.2",
23+
"version": "0.9.3-alpha.1",
2424
"changelog": {
2525
"repo": "aceHubert/ace-fetch",
2626
"labels": {

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"release": "lerna publish",
1717
"release:git": "lerna publish from-git",
1818
"release:package": "lerna publish from-package",
19-
"release:alpha": "lerna publish --conventional-commits --conventional-prelease --preid alpha --dist-tag alpha",
20-
"release:next": "lerna publish --conventional-commits --conventional-prelease --preid next --dist-tag next",
19+
"release:alpha": "lerna publish --conventional-commits --conventional-prerelease --preid alpha --dist-tag alpha",
20+
"release:next": "lerna publish --conventional-commits --conventional-prerelease --preid next --dist-tag next",
2121
"release:graduate": "lerna publish --conventional-commits --conventional-graduate",
2222
"clean": "lerna clean --yes",
2323
"lint": "lerna run lint --parallel --stream",
@@ -31,6 +31,7 @@
3131
"@babel/cli": "^7.9.0",
3232
"@babel/core": "^7.9.0",
3333
"@babel/preset-env": "^7.9.0",
34+
"@babel/preset-react": "^7.26.3",
3435
"@babel/preset-typescript": "^7.16.7",
3536
"@commitlint/cli": "^12.1.4",
3637
"@commitlint/config-conventional": "^12.1.4",
@@ -72,6 +73,7 @@
7273
"less": "^4.1.2",
7374
"less-plugin-npm-import": "^2.1.0",
7475
"lint-staged": "^10.2.0",
76+
"next": "^15.1.7",
7577
"nodemon": "^2.0.2",
7678
"nuxt": "^3.0.0",
7779
"postcss": "^8.4.12",
@@ -88,7 +90,7 @@
8890
"ts-jest": "^26.0.0",
8991
"ts-loader": "^8.0.3",
9092
"ts-node": "^10.7.0",
91-
"typescript": "^4.1.5",
93+
"typescript": "^4.9.5",
9294
"util": "^0.12.1",
9395
"yorkie": "^2.0.0"
9496
},

packages/react/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
## [0.9.3-alpha.1](https://github.com/aceHubert/ace-fetch/compare/v0.9.3-alpha.0...v0.9.3-alpha.1) (2025-02-20)
7+
8+
### Bug Fixes
9+
10+
- reack hook 在组件外使用问题 ([00430af](https://github.com/aceHubert/ace-fetch/commit/00430af98440c2c1d08cdbd0da72e749330e6e49))
11+
12+
## [0.9.3-alpha.0](https://github.com/aceHubert/ace-fetch/compare/v0.9.2...v0.9.3-alpha.0) (2025-02-20)
13+
14+
### Features
15+
16+
- add react support ([ec9e444](https://github.com/aceHubert/ace-fetch/commit/ec9e444cd863038517271dfc62b5e964beb03d64))

packages/react/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## @ace-fetch/react
2+
3+
> react adapter and typing for `@ace-fetch/core`
4+
5+
6+
## 安装
7+
8+
```bash
9+
yarn add @ace-fetch/react
10+
或者
11+
npm i -S @ace-fetch/react
12+
```
13+
14+
<br>
15+
16+
## 使用方法
17+
18+
### Define Regist Api
19+

packages/react/babel.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
modules: false, // 对ES6的模块文件不做转化,以便使用tree shaking、sideEffects等
7+
spec: false,
8+
forceAllTransforms: true,
9+
useBuiltIns: 'usage', // 根据使用导入
10+
corejs: {
11+
version: 3, // 使用core-js@3
12+
proposals: false,
13+
},
14+
},
15+
],
16+
[
17+
'@babel/preset-react',
18+
{
19+
runtime: 'automatic',
20+
},
21+
],
22+
['@babel/preset-typescript'],
23+
],
24+
ignore: ['src/*.d.ts'],
25+
};

packages/react/package.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "@ace-fetch/react",
3+
"version": "0.9.3-alpha.1",
4+
"author": "Hubert<[email protected]>",
5+
"description": "react adapter for @ace-fetch/core.",
6+
"main": "lib/index.js",
7+
"module": "esm/index.js",
8+
"umd:main": "dist/index.umd.production.js",
9+
"unpkg": "dist/index.umd.production.js",
10+
"jsdelivr": "dist/index.umd.production.js",
11+
"exports": {
12+
".": {
13+
"import": "./esm/index.js",
14+
"require": "./lib/index.js"
15+
},
16+
"./*": {
17+
"import": [
18+
"./*",
19+
"./esm/*"
20+
],
21+
"require": [
22+
"./*",
23+
"./lib/*"
24+
],
25+
"default": {
26+
"import": "./esm/*/index.js",
27+
"require": "./lib/*/index.js"
28+
}
29+
}
30+
},
31+
"keywords": [
32+
"react",
33+
"ace-fetch",
34+
"fetch",
35+
"microfront"
36+
],
37+
"files": [
38+
"dist",
39+
"lib",
40+
"esm"
41+
],
42+
"scripts": {
43+
"serve": "run -T next dev playground --port 7003",
44+
"build": "run -T rimraf -rf lib esm dist && yarn build:version && yarn build:cjs && yarn build:esm && yarn build:umd",
45+
"build:version": "node -p \"'export const version: string = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
46+
"build:cjs": "run -T tsc --project tsconfig.build.json",
47+
"build:esm": "run -T tsc --project tsconfig.build.json --module es2015 --outDir esm",
48+
"build:umd": "run -T rollup --config --bundleConfigAsCjs",
49+
"lint": "run -T eslint . --cache --report-unused-disable-directives --ignore-path=../../.eslintignore",
50+
"lint:fix": "run -T eslint . --cache --fix --ignore-path=../../.eslintignore"
51+
},
52+
"license": "MIT",
53+
"repository": {
54+
"type": "git",
55+
"url": "https://github.com/aceHubert/ace-fetch.git",
56+
"directory": "packages/react"
57+
},
58+
"bugs": {
59+
"url": "https://github.com/aceHubert/ace-fetch/issues"
60+
},
61+
"dependencies": {
62+
"@ace-fetch/core": "^0.9.1",
63+
"@ace-util/core": "^0.3.0"
64+
},
65+
"devDependencies": {
66+
"@types/react": "^18.2.0",
67+
"@types/react-dom": "^18.2.0",
68+
"react": "^18.2.0",
69+
"react-dom": "^18.2.0"
70+
},
71+
"peerDependencies": {
72+
"react": ">=18.2.0"
73+
},
74+
"publishConfig": {
75+
"access": "public"
76+
}
77+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import axios from 'axios';
2+
import { createFetch } from '@ace-fetch/react';
3+
4+
const axiosInstance = axios.create({
5+
timeout: 10000,
6+
});
7+
8+
export const fetch = createFetch(axiosInstance);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { typedUrl } from '@ace-fetch/core';
2+
import { defineRegistApi } from '@ace-fetch/react';
3+
4+
export type User = {
5+
id: number;
6+
firstName: string;
7+
lastName: string;
8+
city: string;
9+
};
10+
11+
export const useUserApi = defineRegistApi('user', {
12+
apis: {
13+
getUsers: typedUrl<User[]>`get /users`,
14+
getUser: typedUrl<User, { id: string | number }>`/user/${'id'}`,
15+
addUser: typedUrl<User, any, Partial<Omit<User, 'id'>>>`post /user`,
16+
},
17+
prefix: 'http://localhost:7009',
18+
});

0 commit comments

Comments
 (0)