我从“解码的令牌”中获取“用户”并将该用户设置为状态,但是尽管“用户”具有值,但值并未存储在状态中。
这是我的代码。
class Complainer extends Component {
state = {};
componentDidMount() {
const user = auth.getCurrentUser();
console.log(user);
this.setState({ user });
if (!user) window.location = '/';
}
但用户没有被存储在状态中。请帮忙。