1.2.0 • Published 7 years ago

@pinnacleio/react-event v1.2.0

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

React Event

Declarative way to handle events outside / inside of React Component.

Build Status npm.io

Example

import enhanceWithEvent from '@pinnacleio/react-event'

class HelloWorld extends Component {
  handleEvent() { /* Do whatever you want :) */ }
  render() { return <div /> }
}

// This component calls `handleEvent` method when `mousedown` is fired anywhere.
const Foo = enhanceWithEvent('mousedown')(HelloWorld)

// This component calls `handleEvent` method when `mousedown` is fired inside it.
const Bar = enhanceWithEvent('mousedown', { inside: true })(HelloWorld)

// This component calls `handleEvent` method when `mousedown` is fired outside of it.
const Baz = enhanceWithEvent('mousedown', { outside: true })(HelloWorld)

API

Our component must define method handleEvent() in order for enhancer to work, otherwise nothing will happen.

enhanceWithEvent(
  events: String | Array<String>, 
  options: Object,
): HigherOrderComponent
ParameterDescriptionExampleDefault Value
eventsEvent type(s) to listen for.'mousedown', ['mousedown', 'touchstart']Null
optionsWhere event will be accepted.{ outside: true }, { inside: true }{}
1.2.0

7 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago