~700B React Click Away Listener.


yarn add react-click-away-listener
  • It's quite small in size.
  • It's built with TypeScript.
  • It supports both Mouse and Touch Events.
  • It works with Portals.


import ClickAwayListener from 'react-click-away-listener';

const App = () => {
	const handleClickAway = () => {
		console.log('Hey, you can close the Popup now');

	return (
		<div id="app">
			<ClickAwayListener onClickAway={handleClickAway}>
				<div> Some Popup, Nav or anything </div>
			<div id="something-else">Hola, mi amigos</div>


  • Ensure the ClickAway component has just one child else React.only will throw an error.
  • It doesn't work with Text nodes.


Prop Default value Description
onClickAway undefined Fires when a user clicks outside the click away component
as div The rendered element type
mouseEvent click The mouse event type that gets fired on ClickAway
touchEvent touchend The touch event type that gets fired on ClickAway