728x90
반응형
useFullscreen
이미지를 Fullscreen으로 만드는 hooks를 만들어보자
useFullscreen
Make fullscreen 버튼 클릭시 이미지 fullscreen, Exit fullscreen 버튼 클릭시 fullscreen 빠져나오기
const useFullscreen = () => {
const element = useRef();
const triggerFull = () => {
if (element.current) {
element.current.requestFullscreen();
}
};
const exitFull = () => {
document.exitFullscreen();
};
return { element, triggerFull, exitFull };
};
const App = () => {
const { element, triggerFull, exitFull } = useFullscreen();
return (
<div className="App" style={{ height: "1000vh" }}>
<div ref={element}>
<img src="https://image.genie.co.kr/Y/IMAGE/IMG_ARTIST/080/044/692/80044692_1664500054593_28_600x600.JPG"></img>
</div>
<button onClick={exitFull}>Exit fullscreen</button>
<button onClick={triggerFull}>Make fullscreen</button>
</div>
);
};
반응형
'프로그래밍 > React' 카테고리의 다른 글
[React] React Hooks (11) - useConfirm, usePreventLeave (0) | 2023.02.08 |
---|---|
[React] React Hooks (10) - useNotification (0) | 2023.02.07 |
[React] React Hooks (8) - useScroll (0) | 2023.02.03 |
[React] React Hooks (7) - useFadeIn (0) | 2023.02.02 |
[React] React Hooks (6) - useBeforeLeave (0) | 2023.02.01 |