about summary refs log tree commit diff
path: root/src/components/Dialog/utils.ts
blob: 812e8cca158f0a1a6969d045aff3f04237c8766d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import React from 'react'

import {type DialogControlProps} from '#/components/Dialog/types'

export function useAutoOpen(control: DialogControlProps, showTimeout?: number) {
  React.useEffect(() => {
    if (showTimeout) {
      const timeout = setTimeout(() => {
        control.open()
      }, showTimeout)
      return () => {
        clearTimeout(timeout)
      }
    } else {
      control.open()
    }
  }, [control, showTimeout])
}