@rscc/common-react
v0.2.0
Published
RSCC 공통 React 훅 — useDebounce, useSse (@rscc/common-core 의 SSE 파서 래핑).
Maintainers
Readme
@rscc/common-react
RSCC 공통 React 훅 — useDebounce, useSse. @rscc/common-core 의 SSE 파서(readSseStream)를 React 상태로 래핑한다.
설치
npm i @rscc/common-react- peerDependencies:
react >= 18— 소비 앱이 직접 설치 @rscc/common-core는^범위 의존으로 함께 설치된다 (두 패키지는 락스텝 버전)- Node >= 18, ESM + CJS 듀얼 빌드, 타입 선언 동봉
훅
| 훅 | 시그니처 | 설명 |
|---|---|---|
| useDebounce | useDebounce<T>(value, delayMs = 200): T | 마지막 안정 값만 통과 — 자동완성 API 호출 절감 |
| useSse | useSse(options?) → { start, cancel, text, sources, conversationId, error, isStreaming } | SSE 구독 상태 훅 — 언마운트 시 자동 중단 |
사용 예시
useDebounce
import { useDebounce } from "@rscc/common-react";
const debounced = useDebounce(keyword, 200);
// debounced 가 바뀔 때만 자동완성 API 호출useSse
import { useSse } from "@rscc/common-react";
const { start, cancel, text, sources, conversationId, error, isStreaming } = useSse();
await start("/api/v1/chat/stream", { method: "POST", headers, body });
// text: delta 누적 텍스트, sources: RAG 근거, error: in-band 오류 메시지
// cancel(): 중단 — 그때까지의 text 는 보존되고 error 는 남지 않는다- 구독 전 검증 실패(
!res.ok)는 응답 봉투의message를error로 노출한다. start재호출 시 이전 스트림을 중단하고 상태를 초기화한다.- 한계:
[DONE]정상 종료와 끊긴 스트림을 구분하는 신호가 없다 — 둘 다isStreaming=false,error=null로 끝난다.
문서 / 저장소
- 상세 문서: js/README.md
- SSE 프레임 계약: contracts/sse-frames.md
- 저장소: Jeonghyeon-Ryu/r-common · MIT
