Skip to content

Commit

Permalink
fix: don't useLayoutEffect on server side
Browse files Browse the repository at this point in the history
fix #115
  • Loading branch information
jedwards1211 committed Dec 15, 2022
1 parent 4dc1bc7 commit e58a854
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/useEvent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as React from 'react'

export function useEvent<Fn extends (...args: any[]) => any>(handler: Fn): Fn {
if (typeof window === 'undefined') {
// useLayoutEffect doesn't work on the server side, don't bother
// trying to make callback functions stable
return handler
}

const handlerRef = React.useRef<Fn | null>(null)

React.useLayoutEffect(() => {
Expand Down

0 comments on commit e58a854

Please sign in to comment.