본문으로 건너뛰기

ThrottleButton

비동기 함수를 실행할 때 중복 클릭을 방지해 주는 버튼 컴포넌트입니다. 클릭 후 일정 시간 동안 재클릭을 막아 네트워크 요청을 안전하게 처리할 수 있습니다.

기본 사용법

import { ThrottleButton } from '@0610studio/zs-ui';

<ThrottleButton
primaryLabelComponent={<Text>저장</Text>}
primaryOnPress={async () => {
await saveData();
}}
/>

Props

이름타입기본값설명
loadingComponentReact.ReactNode<ActivityIndicator />로딩 중 표시할 컴포넌트
disabledbooleanfalse비활성화 여부
primaryOnPress() => Promise<void>Required버튼 클릭 시 실행될 비동기 함수
primaryLabelComponentReact.ReactNodeRequired버튼에 표시될 컴포넌트
primaryButtonStyleTouchableOpacityProps['style']{}버튼 스타일
marginHorizontalnumber20좌우 여백
marginBottomnumber20하단 여백
onError(error: Error) => voidundefined비동기 함수 실행 중 오류 발생 시 호출되는 함수

ThrottleButton은 debounce(300ms)와 throttle(2초)이 적용되어 빠른 연속 클릭을 방지하며, 비동기 함수가 종료될 때까지 로딩 상태를 유지합니다.