// sdk · React
Người bạn đồng hành React của @astroway/sdk
Chính thức `@astroway/react` trên npm — một lớp bọc mỏng theo phong cách Stripe cho `@astroway/sdk`. `AstrowayProvider` nâng client lên ngữ cảnh React; các hook `useAstroway`, `useAstrowayQuery`, `useNatalChart` trả về một bộ ba `{ data, error, loading }` theo phong cách SWR mà không có phụ thuộc bên ngoài. Hoạt động với React 18+, Next.js App Router (qua "use client"), Vite, CRA.
// 01 / install
Cài đặt
npm install @astroway/react @astroway/sdk react import: import { AstrowayProvider, useNatalChart } from '@astroway/react';
Xem trong sổ đăng ký → @astroway/react
// 02 / highlights
Điểm nổi bật
- Ngữ cảnh AstrowayProvider
- useAstrowayQuery + useNatalChart
- Không có phụ thuộc ngoài react
- Người bạn đồng hành theo phong cách Stripe
- Toàn bộ loại TypeScript từ @astroway/sdk
// 03 / first request
Yêu cầu đầu tiên
import { AstrowayProvider, useNatalChart } from '@astroway/react';
function App() {
return (
<AstrowayProvider options={{ apiKey: import.meta.env.VITE_AW_KEY }}>
<Chart />
</AstrowayProvider>
);
}
function Chart() {
const { data, error, loading } = useNatalChart({
date: '1990-07-14',
time: '14:30:00',
timezoneOffset: 3,
latitude: 50.4501,
longitude: 30.5234,
});
if (loading) return <p>Loading…</p>;
if (error) return <p>Error: {error.message}</p>;
return <pre>{JSON.stringify(data, null, 2)}</pre>;
} Bắt đầu với React
10.000 credits miễn phí mỗi tháng. SDK mã nguồn mở, được tạo từ OpenAPI 3.1, luôn đồng bộ với backend.