feat: react-swipeable 설치 + useIsMobile/useSwipe 훅 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
18
src/hooks/useIsMobile.js
Normal file
18
src/hooks/useIsMobile.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
const MOBILE_BREAKPOINT = 768;
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = useState(
|
||||
() => window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT}px)`).matches
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT}px)`);
|
||||
const handler = (e) => setIsMobile(e.matches);
|
||||
mql.addEventListener('change', handler);
|
||||
return () => mql.removeEventListener('change', handler);
|
||||
}, []);
|
||||
|
||||
return isMobile;
|
||||
}
|
||||
13
src/hooks/useSwipe.js
Normal file
13
src/hooks/useSwipe.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useSwipeable } from 'react-swipeable';
|
||||
|
||||
export function useSwipe({ onSwipedLeft, onSwipedRight, threshold = 50 } = {}) {
|
||||
const handlers = useSwipeable({
|
||||
onSwipedLeft,
|
||||
onSwipedRight,
|
||||
delta: threshold,
|
||||
trackMouse: false,
|
||||
preventScrollOnSwipe: true,
|
||||
});
|
||||
|
||||
return handlers;
|
||||
}
|
||||
Reference in New Issue
Block a user