airbnb / react-outside-click-handler

OutsideClickHandler component for React.
MIT License
614 stars 65 forks source link

not working on server side rendering(nextjs) #39

Open purskills opened 4 years ago

purskills commented 4 years ago

always firing outside click event on server-side rendering.

to reproduce, use the sample code.

ljharb commented 4 years ago

I’m not sure what you mean - there’s no events in server side rendering to fire.

john1625b commented 3 years ago

Same, Also it logs 8 clicks outside for every 1 click

ljharb commented 3 years ago

There are no clicks in serverside rendering. Perhaps you're seeing this in the browser?

Cmoen11 commented 1 week ago

You're welcome :-)

import BaseOutsideClickHandler from 'react-outside-click-handler'

export function OutsideClickHandler({
    children,
    onOutsideClick,
}: {
    children: React.ReactNode
    onOutsideClick: () => void
}) {
    if (typeof document === 'undefined') {
        return children
    }
    return (
        <BaseOutsideClickHandler onOutsideClick={onOutsideClick}>
            {children}
        </BaseOutsideClickHandler>
    )
}