我应该如何在React中的模型中使用函数

时间:2019-05-29 12:54:20

标签: reactjs

我有一个用户,我想在模型中创建一个辅助函数,以查看用户是否为Admin,例如:

export class User {
    email;
    password;
    profile;

    constructor(email, password, profile) {
        this.email = email;
        this.password = password;
        this.profile = profile;
    }

    isAdmin() {
        return this.profile && this.profile.name === "ADMIN"
    }
}

并致电:

<BrowserRouter>
    <div>
        <Switch>
           {(user.isAdmin()) && <Redirect to={`/route`}/>}
        </Switch>
    </div>
</BrowserRouter>

但是我得到:

TypeError: user.isAdmin is not a function

我应该怎么做?我使用Redux

0 个答案:

没有答案