@@ -79,6 +79,14 @@ const getIndexProgress = (flicking: Flicking) => {
7979 * 이 타입은 Flicking 인스턴스의 상태가 변경될 때 자동으로 업데이트되는
8080 * 반응형 상태 속성들과 메서드들을 제공합니다.
8181 * @typedef
82+ * @see {@link https://naver.github.io/egjs-flicking/Demos#reactive-api-demo }
83+ * @example
84+ * ```jsx
85+ * const flickingRef = React.useRef(null);
86+ * const {
87+ * progress
88+ * } = useFlickingReactiveAPI(flickingRef);
89+ * ```
8290 */
8391export type FlickingReactiveObject = ReactiveObject < FlickingReactiveState & FlickingReactiveMethod > ;
8492
@@ -141,9 +149,46 @@ export interface FlickingReactiveData {
141149 /**
142150 * Flicking options used for initialization<ko>초기화에 사용되는 Flicking 옵션</ko>
143151 */
144- options : FlickingOptions | undefined ;
152+ options : FlickingReactiveAPIOptions | undefined ;
145153}
146154
155+ /**
156+ * Options for Flicking reactive API that help optimize initial rendering in SSR scenarios
157+ * These options allow you to set initial state values before the Flicking instance is fully initialized,
158+ * preventing unnecessary re-renders when the actual Flicking state is applied.
159+ * @ko SSR 상황 등에서 초기 렌더링을 최적화할 수 있게 하는 Flicking 반응형 API 옵션
160+ * 이 옵션들을 통해 Flicking 인스턴스가 완전히 초기화되기 전에 초기 상태 값을 설정할 수 있어,
161+ * 실제 Flicking 상태가 적용될 때 불필요한 리렌더링을 방지할 수 있습니다.
162+ * @typedef
163+ * @example
164+ * ```js
165+ * const options = {
166+ * defaultIndex: 2,
167+ * totalPanelCount: 5
168+ * };
169+ * const reactiveObj = connectFlickingReactiveAPI(flicking, options);
170+ * ```
171+ */
172+ export interface FlickingReactiveAPIOptions {
173+ /**
174+ * Initial panel index to start with. This sets the currentPanelIndex and indexProgress initial values.
175+ * Also affects isReachStart calculation (true when defaultIndex is 0).
176+ * @ko 시작할 초기 패널 인덱스. currentPanelIndex와 indexProgress의 초기값을 설정합니다.
177+ * 또한 isReachStart 계산에도 영향을 줍니다 (defaultIndex가 0일 때 true).
178+ * @default 0
179+ */
180+ defaultIndex : number ;
181+ /**
182+ * Total number of panels in the Flicking instance. This sets the totalPanelCount initial value
183+ * and helps prevent layout shifts during SSR hydration.
184+ * @ko Flicking 인스턴스의 전체 패널 개수. totalPanelCount의 초기값을 설정하며
185+ * SSR 하이드레이션 과정에서 레이아웃 시프트를 방지하는 데 도움이 됩니다.
186+ * @default 0
187+ */
188+ totalPanelCount : number ;
189+ }
190+
191+
147192/**
148193 * Internal reactive API adapter for Flicking that manages state and event listeners
149194 * This adapter is used internally by framework-specific packages (react-flicking, vue-flicking, etc.)
@@ -166,7 +211,7 @@ FlickingReactiveData
166211
167212 // Move to a specific panel index
168213 const moveTo = ( i : number ) => {
169- if ( flicking === undefined ) {
214+ if ( flicking == null ) {
170215 return Promise . reject ( new Error ( "Flicking instance is not available" ) ) ;
171216 }
172217 if ( flicking ?. animating ) {
@@ -181,12 +226,12 @@ FlickingReactiveData
181226 // options를 고려하지 않고 초기값을 설정해도 동작에는 아무런 문제가 없으나, 이 시점의 초기값과 컴포넌트 init 단계에서의 초기값이 다르면 화면 리렌더링이 발생할 수 있으므로
182227 // 이렇게 미리 옵션을 통해서 예측할 수 있는 부분들은 맞춰둔다.
183228 const reactiveObj : FlickingReactiveObject = reactive ( {
184- isReachStart : ( options ?. defaultIndex === 0 && ! options . circular ) ,
229+ isReachStart : options ?. defaultIndex === 0 ,
185230 isReachEnd : false ,
186- totalPanelCount : 0 ,
231+ totalPanelCount : options ?. totalPanelCount ?? 0 ,
187232 currentPanelIndex : options ?. defaultIndex ?? 0 ,
188233 progress : 0 ,
189- indexProgress : 0 ,
234+ indexProgress : options ?. defaultIndex ?? 0 ,
190235 moveTo
191236 } ) ;
192237
@@ -244,7 +289,7 @@ FlickingReactiveData
244289 * Connect Flicking instance to reactive API
245290 * @ko Flicking 인스턴스를 반응형 API에 연결합니다
246291 * @param {Flicking } flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
247- * @param {FlickingOptions } [options] - Flicking options<ko>Flicking 옵션</ko>
292+ * @param {FlickingReactiveAPIOptions } [options] - Flicking options<ko>Flicking 옵션</ko>
248293 * @returns {FlickingReactiveObject } Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
249294 * @example
250295 * ```js
@@ -270,7 +315,7 @@ FlickingReactiveData
270315 * reactiveObj.moveTo(2); // Move to third panel
271316 * ```
272317 */
273- const connectFlickingReactiveAPI = ( flicking : Flicking , options ?: FlickingOptions ) => {
318+ const connectFlickingReactiveAPI = ( flicking : Flicking , options ?: FlickingReactiveAPIOptions ) => {
274319 const obj = adaptReactive ( flickingReactiveAPIAdapter , ( ) => ( { flicking, options } ) ) ;
275320 obj . mounted ( ) ;
276321 const instance = obj . instance ( ) ;
0 commit comments