react-redux-values
v1.1.2
Published
get and set values from a redux store in a declarative way
Downloads
4
Maintainers
Readme
react-redux-values
Get and Set values from a redux store in a declarative way
Table of Contents
Install
yarn add --dev react-redux-values
Usage
store.js:
import { reducer } from 'react-redux-values';
import { createStore, combineReducers } from 'redux';
export default createStore(
combineReducers({
values: reducer
})
);
app.js:
import Value from 'react-redux-values';
export default () => (
<Value name="hey" initialValue="oh">
{({ value, onValueChange }) => (
<p onClick={() => onValueChange('heyoh')}>{value}</p>
)}
</Value>
);
with-connect.js:
import Value, { set } from 'react-redux-values';
import { connect } from 'react-redux';
const Div = ({ handleClick }) => (
<Value name="hey" initialValue="oh">
{({ value }) => <p onClick={handleClick}>{value}</p>}
</Value>
);
export default connect(null, dispatch => ({
handleClick: () => dispatch(set({ name: 'hey', value: 'heyoh' }))
}))(Div);
License
BSD-3-Clause