1.0.1 • Published 3 years ago

react-outside-click-event v1.0.1

Weekly downloads
4
License
MIT
Repository
-
Last release
3 years ago

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