ink-redux
v1.0.0
Published
Redux bindings for Ink
Downloads
107
Readme
ink-redux
Redux bindings for Ink.
Install
$ npm install --save ink-redux
Usage
const {h, mount, Component} = require('ink');
const {Provider, connect} = require('ink-redux');
const store = createStore((state = 0, action) => {
switch (action.type) {
case 'INCREMENT': return state + 1;
default: return state;
}
});
class Counter extends Component {
render(props) {
return `Counter: ${props.counter}`;
}
componentDidMount() {
this.timer = setInterval(this.props.onIncrement, 100);
}
componentWillUnmount() {
clearInterval(this.timer);
}
}
const mapStateToProps = state => ({
counter: state
});
const mapDispatchToProps = {
onIncrement: () => ({type: 'INCREMENT'})
};
const ConnectedCounter = connect(mapStateToProps, mapDispatchToProps)(Counter);
mount((
<Provider store={store}>
<ConnectedCounter/>
</Provider>
));
API
See react-redux for documentation.
Differences
- Matches API of
redux@4
- Doesn't support
options
inconnect()
- Doesn't support returning a function from
mapStateToProps()
License
MIT © Vadim Demedes