(fn: () => boolean)
| 1 | import * as Solid from 'solid-js' |
| 2 | |
| 3 | export const usePrevious = (fn: () => boolean) => { |
| 4 | return Solid.createMemo( |
| 5 | ( |
| 6 | prev: { current: boolean | null; previous: boolean | null } = { |
| 7 | current: null, |
| 8 | previous: null, |
| 9 | }, |
| 10 | ) => { |
| 11 | const current = fn() |
| 12 | |
| 13 | if (prev.current !== current) { |
| 14 | prev.previous = prev.current |
| 15 | prev.current = current |
| 16 | } |
| 17 | |
| 18 | return prev |
| 19 | }, |
| 20 | ) |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * React hook to wrap `IntersectionObserver`. |