convex-create-component은(는) 무엇을 하나요?
재사용 가능한 Convex 컴포넌트를 독립된 테이블과 앱 노출 API와 함께 구축합니다. 새 컴포넌트, 재사용 가능한 백엔드 모듈, 통합, 또는 컴포넌트 경계 작업에 사용하세요.
사용법
새 컴포넌트 생성
npx convex component <component-name>
이 명령어는 현재 디렉토리에 <component-name> 폴더를 생성하고 템플릿 코드를 설정합니다.
컴포넌트 업그레이드
npx convex component:upgrade
이 명령어는 기존 컴포넌트를 최신 템플릿과 동기화합니다.
지원 플랫폼
- Convex App
- Node.js
- React
설정
컴포넌트는 convex.json 파일을 통해 설정됩니다. 주요 옵션은 다음과 같습니다.
| 옵션 | 설명 | 필수 여부 |
|---|---|---|
name | 컴포넌트 이름 | 예 |
tables | 격리된 테이블 정의 | 아니요 |
api | 앱 노출 API 함수 | 아니요 |
예제
// convex/myComponent.ts
import { component } from "convex/component";
export const myComponent = component({
name: "my-component",
tables: {
items: {
name: v.string(),
count: v.number(),
},
},
api: {
getItems: async (ctx) => {
return await ctx.db.query("items").collect();
},
},
});