假设您有以下index.js
代码:
const App = memo(props => {
return (
<Layout>
// you can consider below code as a switch case
{
{
'NO_SESSION': <Login />,
'NOTCONFIRMED_SESSION': <Confirm />
'CONFIRMED_SESSION': <Home />
}[sessionState]
}
</Layout>
);
});
ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();
某些逻辑的sessionState
结果取决于IndexedDB
. 代码是这样的:
const getSessionState = () => {
if(// there is no session)
return "NO_SESSION"
else if(// there is not confirmed session)
return "NOTCONFIRMED_SESSION"
else if(// there is confirmed session)
return "CONFIRMED_SESSION"
}
所以我的问题:
使用它是否合理
react-hooks
?如果是如何实施?