我正在redux中创建一个简单的登录表单,但我注销后似乎无法删除用户令牌。我已经尝试过js-cookie,react-cookie和现在的document.cookie,但都没有清除我的sloev_concerts_01
。
如何从React Redux组件中删除Cookie?
import React, { Component } from 'react';
import { connect } from "react-redux";
import { withCookies } from 'react-cookie';
import Cookies from 'js-cookie';
import ArtistSearch from './artistSearch'
import LoginForm from './loginForm'
import * as actions from '../redux/actions'
class Root extends Component {
componentDidMount() {
this.props.login();
Cookies.remove('sloev_concerts_01')
}
logout = () => {
console.log("removing cookie")
const { cookies } = this.props;
document.cookie = "sloev_concerts_01=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
this.props.logout()
}
render() {
return (
<div>
{this.props.me.empty ?
<LoginForm/>
:
(
<div>
<button onClick={this.logout.bind(this)}>Logout</button>
<ArtistSearch />
</div>
)
}
</div>
)
}
}
const mapStateToProps = (state, ownProps) => {
return {
me: state.me,
cookies: ownProps.cookies
};
};
const mapDispatchToProps = dispatch => {
return {
login: () => dispatch(actions.performLogin()),
logout: () => dispatch(actions.performLogout())
};
};
export default withCookies(connect(mapStateToProps, mapDispatchToProps)(Root));