You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, just leaving this Issue here for anyone wanting to write this as a Next.js Typescript hook.
In src/support.js, make sure to check for process.browser or you'll get a document is undefined error. This is due to SSR, I think.
const getSupport = () => {
if (process.browser) {
return {
hasWheelEvent: "onwheel" in document,
hasMouseWheelEvent: "onmousewheel" in document,
hasTouch: "ontouchstart" in document,
hasTouchWin: navigator.msMaxTouchPoints && navigator.msMaxTouchPoints > 1,
hasPointer: !!window.navigator.msPointerEnabled,
hasKeyDown: "onkeydown" in document,
isFirefox: navigator.userAgent.indexOf("Firefox") > -1,
}
}
}
export default getSupport
Hook :
import VirtualScroll from "libs/virtual-scroll/src/index"
import { useEffect, MutableRefObject } from "react"
export type VirtualScrollEvent = {
x: number // total distance scrolled on the x axis
y: number // total distance scrolled on the y axis
deltaX: number // distance scrolled since the last event on the x axis
deltaY: number // distance scrolled since the last event on the y axis
originalEvent: Event // the native event triggered by the pointer device or keyboard
}
type VirtualScrollCallback = (e: VirtualScrollEvent) => void
const useVirtualScroll = (
ref: MutableRefObject<HTMLElement>,
callback: VirtualScrollCallback,
dependencies: any = [],
) => {
useEffect(() => {
if (ref.current) {
const instance = new VirtualScroll(ref.current)
instance.on((e: VirtualScrollEvent) => callback(e))
return () => {
instance.destroy()
}
}
}, dependencies)
return typeof window !== "undefined"
}
export default useVirtualScroll
Hey, just leaving this Issue here for anyone wanting to write this as a Next.js Typescript hook.
src/support.js
, make sure to check forprocess.browser
or you'll get adocument is undefined
error. This is due to SSR, I think.The text was updated successfully, but these errors were encountered: