// sdk · React
@astroway/sdk の React コンパニオン
公式の `@astroway/react` が npm にあります — `@astroway/sdk` 上の薄い Stripe スタイルのラッパーです。`AstrowayProvider` はクライアントを React コンテキストに持ち上げます。`useAstroway`、`useAstrowayQuery`、`useNatalChart` フックは、外部依存関係がゼロの SWR スタイルの `{ data, error, loading }` トリプルを返します。React 18+、Next.js App Router (「use client」経由で)、Vite、CRA で動作します。
// 01 / install
インストール
npm install @astroway/react @astroway/sdk react インポート: import { AstrowayProvider, useNatalChart } from '@astroway/react';
レジストリで確認する → @astroway/react
// 02 / highlights
特長
- AstrowayProvider コンテキスト
- useAstrowayQuery + useNatalChart
- React 以外の依存関係ゼロ
- Stripe スタイルのコンパニオン
- @astroway/sdk からの完全な TypeScript 型
// 03 / first request
最初のリクエスト
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>;
} Reactを始める
月額10,000クレジットを無料で利用可能。Open-source SDKで、OpenAPI 3.1から自動生成され、常にバックエンドと同期しています。