Initialize React SDK
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# React SDK
|
||||
|
||||
使用 TypeScript 开发的 React SDK,配套 `backend-server`。
|
||||
|
||||
## 开发
|
||||
|
||||
```sh
|
||||
npm ci
|
||||
npm run typecheck
|
||||
npm run build
|
||||
```
|
||||
|
||||
## 使用
|
||||
|
||||
本包尚未发布。先运行 `npm run build`,再在 React 项目中安装本地目录:
|
||||
|
||||
```sh
|
||||
npm install /absolute/path/to/react-sdk
|
||||
```
|
||||
|
||||
```tsx
|
||||
import { useHealth } from "@entroia/react-sdk";
|
||||
|
||||
export function ServerStatus() {
|
||||
const { data, error, loading } = useHealth("http://localhost:8000");
|
||||
if (loading) return <p>加载中</p>;
|
||||
if (error) return <p>{error.message}</p>;
|
||||
return <p>{data?.status}</p>;
|
||||
}
|
||||
```
|
||||
|
||||
非组件场景可以使用 `createClient({ baseUrl }).health()`。
|
||||
Reference in New Issue
Block a user