React Flyd Class
A thin layer between Flyd and React. Ported from react-reactive-class.
What?
With React Flyd Class, you can create Reactive Components, which subscribe to flyd streams and re-render themselves.
Counter example
You can compare this example to Counter example of Cycle.js and Counter example of Yolk.
;;;; const Span = ; { const plusClick$ = ; const minusClick$ = ; const action$ = ; const count$ = ; return <div> <div> <button id="plus" onClick= >+</button> <button id="minus" onClick= >-</button> </div> <div> Count: <Span> count$ </Span> </div> </div> } ReactDOM;
Features
- Reactive wrapper: A higher order component to wrap a React component to be a Reactive Component.
Installation
npm install --save react-flyd-class
Usage
Use Reactive wrapper
Take full control of component lifecycle.
reactive(ReactClass): ReactClass
Example:
;;;;; Component { console; } { console; return <div>thispropschildren</div> ; } { console; } const ReactiveText = ; const currentTime$ = ; ReactDOM;
Mount/unmount Reactive Component
You can use mount
attribute to mount/unmount a component.
// Unmount this component if length of incoming text is 0.<Span mount= text$ > text$</Span>
Child component constraint
Source must be the only child when using observable as child component.
// This will not work<Span> Hello name$ how are you?</Span> // This will work<span> Hello <Span>name$</Span> how are you?</span>
Feedbacks are welcome!
Feel free to ask questions or submit pull requests!
License
The MIT License (MIT)