A utility for connecting a React component with Callbag sources. Comparable to ReactRedux, but for Callbags instead of Redux!
npm install callbag-connect-react
import connect from 'callbag-connect-react
@connect(
{ // Objects are assumed to contain sourcess
propName: source1,
...
},
[ // Arrays are assumed to contain signals
[source2, callback],
...
]
})
class MyComponent extends React {
...
}
Now;
- Whenever
source1
emits data, that will be sent to thepropName
prop inMyComponent
. - Whenever
source2
emits,callback
will be invoked with(componentInstance, emission)
.
An object where the keys are prop names and values are sources. When a source emits, the corresponding prop will be populated.
An array of tuples, each tuple is an array with a source and a callback. Whenever the source emits, the callback will be called with the component instance and the emitted data.
Use signals when you want your component to do something other than render when a source emits.