Skip to content

dev-expert/react-outside-click-event

Repository files navigation

react-outside-click-event

Travis npm package Coveralls

Installation

yarn add react-outside-click-event

Demo

Usage

import HandleOutsideClick from '../../src'

export default function Demo() {

	const [divColor, setDivColor] = useState('yellow');
	return <HandleOutsideClick
		onOutsideClick={() => {
			alert("You click outside this div. Div color will be toggled.");
			setDivColor((val) => val === 'yellow' ? 'green' : 'yellow');
		}}
	>
		<div style={{
			position: 'absolute',
			width: '400px',
			height: '400px',
			display: 'flex',
			justifyContent: 'center',
			alignItems: 'center',
			fontWeight: 'bold',
			fontSize: 'larger',
			backgroundColor: divColor
		}}>Click anywhere outside this box!!</div>
	</HandleOutsideClick>
}

References

About

A React Component that provides you with an onOutsideClickEvent for its child components.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published