All Projects → vadimdemedes → ink-redux

vadimdemedes / ink-redux

Licence: MIT License
Redux bindings for Ink

Programming Languages

javascript
184084 projects - #8 most used programming language

ink-redux Build Status

Redux bindings for Ink.

Install

$ npm install redux ink-redux

Usage

const {h, render, Component} = require('ink');
const {Provider, connect} = require('ink-redux');
const {createStore} = require('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);

render((
	<Provider store={store}>
		<ConnectedCounter/>
	</Provider>
));

API

See react-redux for documentation.

Differences

  • Matches API of redux@4
  • Doesn't support options in connect()
  • Doesn't support returning a function from mapStateToProps()

License

MIT © Vadim Demedes

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].