mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-05 04:38:37 +08:00
30 lines
661 B
TypeScript
30 lines
661 B
TypeScript
'use client'
|
|
import React from 'react'
|
|
|
|
export enum MediaType {
|
|
mobile = 'mobile',
|
|
tablet = 'tablet',
|
|
pc = 'pc',
|
|
}
|
|
|
|
const useBreakpoints = () => {
|
|
const [width, setWidth] = React.useState(globalThis.innerWidth)
|
|
const media = (() => {
|
|
if (width <= 640)
|
|
return MediaType.mobile
|
|
if (width <= 768)
|
|
return MediaType.tablet
|
|
return MediaType.pc
|
|
})()
|
|
|
|
React.useEffect(() => {
|
|
const handleWindowResize = () => setWidth(window.innerWidth)
|
|
window.addEventListener('resize', handleWindowResize)
|
|
return () => window.removeEventListener('resize', handleWindowResize)
|
|
}, [])
|
|
|
|
return media
|
|
}
|
|
|
|
export default useBreakpoints
|