about summary refs log tree commit diff
path: root/src/view/com/lightbox/ImageViewing/hooks/useRequestClose.ts
blob: 4cd03fe71be60034ad1a08e2f96a1779b90547b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Copyright (c) JOB TODAY S.A. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

import {useState} from 'react'

const useRequestClose = (onRequestClose: () => void) => {
  const [opacity, setOpacity] = useState(1)

  return [
    opacity,
    () => {
      setOpacity(0)
      onRequestClose()
      setTimeout(() => setOpacity(1), 0)
    },
  ] as const
}

export default useRequestClose