Skip to content

Commit

Permalink
mapDispatchToProps & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ythosa committed Aug 28, 2020
1 parent 5abd7bd commit 1f4ee4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ export const inc = () => ({ type: 'INC' })

export const dec =() => ({ type: 'DEC' })

export const rnd = (payload) => ({ type: 'RND', payload })
export const rnd = () => {
return {
type: 'RND',
payload: Math.floor(Math.random() * 10),
}
}
9 changes: 8 additions & 1 deletion src/components/counter/counter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import * as actions from '../../actions'

const Counter = ({ counterValue, inc, dec, rnd }) => {
return (
Expand All @@ -24,4 +27,8 @@ const mapStateToProps = (state) => {
}
}

export default connect(mapStateToProps)(Counter)
const mapDispatchToProps = (dispatch) => {
return bindActionCreators(actions, dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(Counter)

0 comments on commit 1f4ee4f

Please sign in to comment.