redux-affix
v1.0.8
Published
A react-redux's connect function with additional shorthand syntax.
Downloads
13
Readme
redux-affix
A react-redux's connect function with additional shorthand syntax.
Usage
affix
behaves exactly like React-Redux's connect
function when mapStateToProps
and mapDispatchToProps
are functions.
Pass single state key as mapStateToProps
affix('todos')
With connect
:
connect(({todos}) => ({todos}))
Pass state keys as mapStateToProps
affix(['todos', 'user'])
With connect
:
connect(({todos, user}) => ({todos, user}))
Pass state paths as mapStateToProps
affix({username: 'user.name', todoCount: 'todos.length'})
With connect
:
connect(({todos, user}) => ({
username: user.name,
todoCount: todos.length
}))
Pass action creators as mapDispatchToProps
affix(mapStateToProps, {onToggleTask: toggleTask})
With connect
:
connect(mapStateToProps, (dispatch) => ({
onToggleTask(taskId) {
return dispatch(toggleTask(taskId));
}
}))