I have a function I am attempting to call in my componentDidMount function. It is function is declared in my mapDispatchToProps function. I am trying to receive variables from the function to display in my render. Instead, I get this error:
TypeError: this.props.pageReload(...).then is not a function
Any advice would help to resolve this issue and hopefully not replicated. I have tried a couple of solutions I ran into but none successful.
Component Level:
import React from 'react';
import { connect } from 'react-redux';
import { Collapse, Container, Navbar, NavbarBrand, NavbarToggler, NavItem, NavLink } from 'reactstrap';
import { Link } from 'react-router-dom';
import { userActions } from '../../../../actions/user.actions';
class InnerHeaderComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
isOpen: false,
First: "",
Last: ""
};
this.toggle = this.toggle.bind(this);
}
componentDidMount() {
this.props.pageReload()
.then((res) => {
this.setState({
First: res.FirstName,
Last: res.LastName
});
});
}
render() {
return();
}
function mapStateToProps(state) {
const { authentication } = state;
const { user } = authentication;
return {
user
};
}
const mapDispatchToProps = dispatch => ({
pageReload: () => dispatch(userActions.pageReload())
});
export default connect(mapStateToProps, mapDispatchToProps)(InnerHeaderComponent);
Actions:
function pageReload() {
return dispatch => {
const user = JSON.parse(localStorage.getItem('user'));
userService._setUserSession(user);
dispatch({ type: userConstants.LOGIN_SUCCESS, user });
console.log(user);
return { FirstName: user.FirstName, LastName: user.LastName };
};
}
https://codesandbox.io/s/new