Binding function withBus
between React and Suber.
Usage
Install:
yarn add react-suber# or npm install react-suber --save
Usage:
// Create a component that will listen on the 'SHOW_WARNING' channel// It expects 'bus' as a propComponent { super thisstate = warning: null } { // Start listening for events on component mount // When something arrives, set component state to the warning message thisstop = thispropsbus } { // Stop listening on unmount this } { // Show the warning (if present) if !thisstatewarning return null return <blink> thisstatewarning </blink> } // Create a component will can send on the 'SHOW_WARNING' channel// when clicked. It expects 'bus' as a propconst SenderButton = { const onClick = bus return <button onClick= onClick > children </button>} // To automatically pass the bus to these components// we wrap them with 'withBus'const WarningBannerWithBus = const SenderButtonWithBus = // We use these wrapped components just as we// would with the original componentsReactDOM
API
Functions
withBus(component)
Returns the wrapped component with the bus
prop injected.
Arguments
component: Component
React component. Can be PureComponent or regular Component
Returns a new React Component
Development setup
yarnnpm run dev