I'm trying to add a User, and for now I am just trying to the calls to work, so there is no data being passed so far. Mycontainer looks like this:
user-add.js
import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {createUser} from '../actions/index'
class UserCreate extends Component {
render() {
return (
<div>
<h2> Add User </h2>
<table className="userTable">
<tbody>
<tr>
<td>First Name:</td>
<td>Last Name:</td>
</tr>
<tr>
<td>
<input type="text"
placeholder="Hello!"
value="Val" />
</td>
<td>
<input type="text"
placeholder="Hello!"
value="Val" />
</td>
</tr>
</tbody>
</table>
<button onClick={() =>this.props.createUser()}>Submit</button>
</div>
);
}
}
function mapStateToProps(state) {
return {
user: state.activeUser
};
}
function matchDispatchToProps(dispatch){
return bindActionCreators({createUser: createUser}, dispatch);
}
export default connect(mapStateToProps)(UserCreate);
switch (action.type) {
case 'USER_DELETED':
return state.filter(user => user.id !== action.userIdToDelete);
case 'USER_CREATED':
return state;
}
export const createUser = () => {
console.log("You created user: XX ");
return {
type: 'USER_CREATED',
payload: {}
}
};
Uncaught TypeError: _this2.props.createUser is not a function(…)
You are not using matchDispatchToProps
(which should be mapDispatchtoProps?
) anywhere.
You need to add it to your connect:
export default connect(mapStateToProps, mapDispatchToProps)(UserCreate);