Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. const mapDispatchToProps = (dispatch) => {
  2. return{
  3. what goes in here?
  4. }
  5. }
  6.  
  7. export default connect(mapStateToProps, mapDispatchToProps)(ComponentName);
  8.  
  9. export const change = value =>({
  10. type: 'CHANGE_FRUIT',
  11. fruit : value
  12. })
  13.  
  14. import { change as changeFruit } from './actions/fruit'
  15.  
  16. const mapDispatchToProps = dispatch =>({
  17. change : fruit => dispatch(changeFruit(fruit))
  18. })
  19.  
  20. dispatch(changeFruit('apple'))
  21.  
  22. import { change as changeFruit } from './actions/fruit'
  23.  
  24. class Component extends React.component{
  25. render(){
  26. const { fruit, change } = this.props
  27. return(
  28. <>
  29. <div>{fruit}</div>
  30. <button onClick={() => change('orange')}>Change to orange</button>
  31. </>
  32. )
  33. }
  34. }
  35.  
  36. const mapStateToProps = state =>({
  37. fruit : state.fruit
  38. })
  39.  
  40. const mapDispatchToProps = dispatch =>({
  41. change : fruit => dispatch(changeFruit(fruit))
  42. })
  43.  
  44. export default connect(mapStateToProps, mapDispatchToProps)(Component)
  45.  
  46. import youraction from './youraction';
  47.  
  48.  
  49. componentDidMount() {
  50. this.props.youractionhandler(action incoming args for example id)
  51. }
  52.  
  53.  
  54. const mapDispatchToProps = dispatch => ({
  55. youractionhandler: action incoming args for example id => dispatch(youraction(action incoming args for example id))
  56. })
  57.  
  58. export default connect(mapStateToProps, mapDispatchToProps)(ComponentName);
  59.  
  60. {
  61. type: 'ADD_TEXT',
  62. value: 'red delicious'
  63. }
  64.  
  65. const addText = value => ({ type: 'ADD_TEXT', value })
  66.  
  67. const action = addText('red delicious') // Create the plain action object
  68. dispatch(action) // Send it to the reducers
  69.  
  70. const mapDispatchToProps = dispatch => ({
  71. addText: value => {
  72. // Same code as above:
  73. const action = addText('red delicious')
  74. dispatch(action)
  75. }
  76. })
  77.  
  78. props.addText('red delicious')
  79.  
  80. <Provider store={store}>
  81.  
  82. const mapDispatchToProps = (dispatch) => {
  83. return{
  84. example look this is dispatch that well happened it will call specif action bu use key type
  85. this == store.dispatch(constants.WIDITHROUP)
  86. the first is key or name of the handle when you want to implement :(input that enters fro this dispatch and=> it call store.dispatch(name of Handel) )
  87. widthroup: (balance) => dispatch({ type: constants.WIDITHROUP ,balance}),
  88. deposit: (balance) => dispatch({ type: constants.DEPOSIT,balance }) }
  89. }
  90. }
  91.  
  92. return {
  93. what goes in here?
  94. }
  95.  
  96. class ColorSelector {
  97. saveSelection () {
  98. dispatch(action); //dispatch is some way to dispatch an action
  99. }
  100. }
  101.  
  102. //I pass my selected color to saveSelection method and that should save
  103. saveSelection(dataToUpdate) {
  104. dispatch({type: actionType, data: dataToUpdate})
  105. }
  106.  
  107. saveSelectionAction(dataToUpdate) {
  108. return {type: actionType, data: dataToUpdate}
  109. }
  110.  
  111. saveSelection(dataToUpdate) {
  112. dispatch(saveSelectionAction(dataToUpdate))
  113. }
  114.  
  115. anotherMethodWhichPassesDispatch(dispatch) {
  116. // unleash the power of closure
  117. return {
  118. saveSelection: saveSelection(dataToUpdate) {
  119. dispatch(saveSelectionAction(dataToUpdate))
  120. }
  121. }
  122. }
  123.  
  124. anotherMethodWhichPassesDispatch(dispatch) {
  125. return {
  126. saveSelection: (dataToUpdate) => {
  127. dispatch(saveSelectionAction(dataToUpdate))
  128. }
  129. }
  130. }
  131.  
  132. saveSelection = (selectedColor) => {
  133. this.props.saveSelection(selectedColor);
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement