Skip to content

BosNaufal/react-click-outside

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Click Outside

A React Component to make a click outside event. Inspired by https://github.com/kentor/react-click-outside

Install

Include react-click-outside.js to your web App file.

Usage

import React from 'react';
import ReactDOM from 'react-dom';

import ClickOutside from './path/to/react-click-outside.js';

class App extends React.Component {

  hasClickedOut(){
    console.log("You've Just Clicked Outside Me!");
  }


  render() {
    return (
      <div>
        <ClickOutside onClickOutside={ () => this.hasClickedOut() }>
          <h1>Box</h1>
        </ClickOutside>
      </div>
    )
  }

}


ReactDOM.render(<App />, document.getElementById("app"))

Why it doesn't Enhance the Component?

Sometime we need mutiple event in the single scope. like,

class Multi extends React.Component {

  handleOne(){ }

  handleTwo(){ }

  render() {
    return (
      <div>
        <ClickOutside onClickOutside={ () => this.handleOne() }>
          <h1>Box</h1>
        </ClickOutside>

        <ClickOutside onClickOutside={ () => this.handleTwo() }>
          <h1>Another Box</h1>
        </ClickOutside>
      </div>
    )
  }

}

Thank You for Making it become useful

Hopefully it can be useful for your next projects.

Let's talk about some projects

Just Contact Me At:

License

MIT Copyright (c) 2016 - forever Naufal Rabbani

About

Click outside event in React Js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published