Skip to content

Instantly share code, notes, and snippets.

View pixelcure's full-sized avatar

Paul Thibedeau pixelcure

  • New York, New York
View GitHub Profile
@TylerK
TylerK / click-outside.tsx
Last active May 8, 2018 10:47
Click outside higher order component for React written in TypeScript
import React from 'react';
import { findDOMNode } from 'react-dom';
type HocWrapper<P> = React.ComponentClass<P> | React.SFC<P>;
function withClickOutside<P, S>(Component: HocWrapper<P>): React.ComponentClass<P> {
class WrappedComponent extends React.Component<P, S> {
private handleClickOutside = e => {
const bounds = this.wrappedDomNode.getBoundingClientRect();
const mouseX = e.clientX || e.pageX;