react event component
A very simple way to manage state in React apps.
Installation
$ npm install --save react-event-component
...or:
$ yarn add react-event-component
Usage
YourComponent.js
'use strict' { superprops thisstate = myValues: } { const myValues = thisstate return <div> There are myValues && myValueslength || 'no' values </div> }
ParentComponent.js
'use strict' Component { globalEventListener } { return <div> <div> <YourComponent listenerId='someEvent' /> </div> <div> <button onClick=thisdoStuff> Add Value </button> </div> </div> } ReactDOM
The example above doesn't look too far away from what already in React, namely this.state
and this.setState()
but the point is that you can import {globalEventListener}
and call globalEventListener.emit('yourEventName')
from anywhere and the component will update.
Have a look in the example/
directory in this repo for a working example, just npm run bundle
to transform ES2015/JSX into ES5 first.