![](/img/trans.png)
[英]Expected an assignment or function call and instead saw an expression React JS
[英]Expression expected with const at React JS component
你能帮我解决这个问题吗?
我想要做的是检查用户是否已注册。 如果已注册,则应显示主页 url,如果未注册,则应显示注册 url。
为此,我查看并检查保存的数据(isRegistered),如果它等于 null 未注册,应显示 /register url。 但它不起作用。
在下一行我有一个错误
const [isReg, setIsReg] = useState(false);
它给了我这个错误:
表达式预期.ts(1109)
const App: React.FC = () => (
const [isReg, setIsReg] = useState<boolean>(false);
if(getItem("isRegistered")==null){
console.log(getItem("isRegistered"));
useState(true);
}
else{
useState(false);
}
<IonApp>
<IonReactRouter>
<IonSplitPane contentId="main" when="(min-width: 4096px)">
<Menu />
<IonRouterOutlet id="main">
<Route path="/" render={() => isReg ? {Home} : {Registro}} />
<Route path="/Favorites" component={Favoritos} exact={true}></Route>
</IonRouterOutlet>
</IonSplitPane>
</IonReactRouter>
</IonApp>
);
它应该是
useEffect(() => {
if(getItem("isRegistered")==null){
console.log(getItem("isRegistered"));
setIsReg(true);
}
else{
setIsReg(false);
}
}, [])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.