SHARE
TWEET

Connect Redux

joygabriel21 Jan 21st, 2020 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import {incrementAction, decrementAction} from './actions'
  4.  
  5. const Counters = (props) => (  
  6.     <div>    
  7.         <h2>{props.counter}</h2>    
  8.         <button onClick={() => props.increment()}>+</button>    
  9.         <button onClick={() => props.decrement()}>-</button>  
  10.     </div>
  11. )
  12.  
  13. const mapStateToProps = (state) => (/*...*/)
  14. const mapDispatchToProps = (dispatch) => ({  
  15.     increment: () => dispatch(incrementAction()),  
  16.     decrement: () => dispatch(decrementAction())
  17. })
  18.  
  19. connect(mapStateToProps,mapDispatchToProps)(Counters)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top