import React from 'react';
import { connect } from 'react-redux';

class ProfilePage extends React.Component {
  constructor(props){
    super(props);
    this.logoff = this.logoff.bind(this);
  }

  logoff(){
    localStorage.setItem('token', '');
    this.props.history.push('/login');
  }

  render(){
    return (
      <div>
        <h1>Profile Page</h1>
        <button onClick={this.logoff}>Log Off</button>
      </div>
    );
  }
}
ProfilePage.propTypes = {
  logout: React.PropTypes.function
};
const mapStateToProps = () => {
  return {
    token: localStorage.token
  };
};

export default connect(mapStateToProps)(ProfilePage);

import React from 'react';
import { connect } from 'react-redux';
import { setChartAction } from '../actions/chartActions';

class ProfilePage extends React.Component {
  constructor(props){
    super(props);
    this.logoff = this.logoff.bind(this);
  }

  logoff(){
    localStorage.setItem('token', '');
    this.props.logout();
    this.props.history.push('/login');
  }

  render(){
    return (
      <div>
        <h1>Profile Page</h1>
        <button onClick={this.logoff}>Log Off</button>
      </div>
    );
  }
}
ProfilePage.propTypes = {
  logout: React.PropTypes.function
};
const mapStateToProps = () => {
  return {
    token: localStorage.token
  };
};
const mapDispatchToProps = dispatch => {
return {
    logout: () => dispatch(setChartAction([]))
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(ProfilePage);

Delete charts in store on logout