Skip to content

[URH-12] useWindowSize 신규 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
🔨 refactor: delayTime 조건에 맞춰 type 적용
  • Loading branch information
foresec committed Jul 9, 2024
commit 965d2ad1b235a85d8141e169dc38cdce33d8bcef
5 changes: 4 additions & 1 deletion src/hooks/useWindowSize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import { PositiveInteger } from '../types/number';

interface WindowSize {
width: number | null;
Expand All @@ -14,7 +15,9 @@ interface WindowSize {
* UI의 세밀한 조작 등 동적인 변화에 유용합니다.
*/

const useWindowSize = (delayTime: number = 200): WindowSize => {
const useWindowSize = <T extends number>(
delayTime: PositiveInteger<T> = 200 as PositiveInteger<T>
): WindowSize => {
const isClient = typeof window === 'object';

const [windowSize, setWindowSize] = useState<WindowSize>({
Expand Down