1 | import ensureFile from './ensure-file.js'
|
2 | import path from 'path'
|
3 |
|
4 | let USE_IS_BEFORE = `// This file is automatically generated by Views and will be overwritten
|
5 | // when the morpher runs. If you want to contribute to how it's generated, eg,
|
6 | // improving the algorithms inside, etc, see this:
|
7 | // https://github.com/viewstools/morph/blob/master/ensure-is-before.js
|
8 | import { useEffect, useState } from 'react'
|
9 |
|
10 | export default function useIsBefore() {
|
11 | let [isBefore, setIsBefore] = useState(true)
|
12 |
|
13 | useEffect(function() {
|
14 | let cancel = false
|
15 | requestAnimationFrame(function() {
|
16 | if (cancel) return
|
17 | setIsBefore(false)
|
18 | })
|
19 | return () => cancel = true
|
20 | }, [])
|
21 |
|
22 | return isBefore
|
23 | }`
|
24 |
|
25 | export default function ensureIsBefore({ src }) {
|
26 | return ensureFile({
|
27 | file: path.join(src, 'Logic', 'useIsBefore.js'),
|
28 | content: USE_IS_BEFORE,
|
29 | })
|
30 | }
|