Skip to content

Instantly share code, notes, and snippets.

@gaurav-gogia
Created May 18, 2018 11:58
Show Gist options
  • Save gaurav-gogia/8a50167b4015385bb3c2746a436a08e5 to your computer and use it in GitHub Desktop.
Save gaurav-gogia/8a50167b4015385bb3c2746a436a08e5 to your computer and use it in GitHub Desktop.
Trying to use mapDispatchToProps without mapStateToProps. See this is what I'm trying but it keeps giving me this error: TypeError: dispatch is not a function
import '../App.css'
import {connect} from 'react-redux';
import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {selectAnimal} from '../actions/actions';
class Animal extends Component {
onClick = () => this.props.selectAnimal(this.props.animalInfo);
render() {
return (
<div className="card no-selection" onClick={this.onClick}>
{this.props.animalInfo.name}
</div>
);
}
}
const mapDispatchToProps = (dispatch) => {
return bindActionCreators({
selectAnimal
}, dispatch)
}
export default connect(mapDispatchToProps)(Animal);
@imshubhamsingh
Copy link

import '../App.css'
import {connect} from 'react-redux';
import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {selectAnimal} from '../actions/actions';

class Animal extends Component {       
    onClick = () => this.props.selectAnimal(this.props.animalInfo);    
    render() {                       
        return (
            <div className="card no-selection" onClick={this.onClick}>
                {this.props.animalInfo.name}                
            </div>
        );
    }
}

export default connect(null, { selectAnimal })(Animal);

@imshubhamsingh
Copy link

import '../App.css';
import { connect } from 'react-redux';
import React, { Component } from 'react';
import { selectAnimal } from '../actions/actions';

const Animal = props => (
  <div
    className="card no-selection"
    onClick={() => props.selectAnimal(props.animalInfo)}
  >
    {props.animalInfo.name}
  </div>
);

export default connect(null, { selectAnimal })(Animal);

@gaurav-gogia
Copy link
Author

That is amazing!! Thanks, ^.^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment