Refactor code style and improve indentation consistency in src/index.js
This commit is contained in:
38
src/index.js
38
src/index.js
@@ -1,33 +1,33 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import React, {useState, useEffect} from 'react';
|
||||
import {createRoot} from 'react-dom/client';
|
||||
import './styles/globals.css';
|
||||
import App from './App';
|
||||
import Login from './components/Auth/Login';
|
||||
|
||||
function Root() {
|
||||
const [authed, setAuthed] = useState(() => localStorage.getItem('auth') === 'true');
|
||||
const [authed, setAuthed] = useState(() => localStorage.getItem('auth') === 'true');
|
||||
|
||||
useEffect(() => {
|
||||
const onStorage = (e) => {
|
||||
if (e.key === 'auth') {
|
||||
setAuthed(e.newValue === 'true');
|
||||
}
|
||||
useEffect(() => {
|
||||
const onStorage = (e) => {
|
||||
if (e.key === 'auth') {
|
||||
setAuthed(e.newValue === 'true');
|
||||
}
|
||||
};
|
||||
window.addEventListener('storage', onStorage);
|
||||
return () => window.removeEventListener('storage', onStorage);
|
||||
}, []);
|
||||
|
||||
const handleLogin = () => {
|
||||
setAuthed(true);
|
||||
};
|
||||
window.addEventListener('storage', onStorage);
|
||||
return () => window.removeEventListener('storage', onStorage);
|
||||
}, []);
|
||||
|
||||
const handleLogin = () => {
|
||||
setAuthed(true);
|
||||
};
|
||||
|
||||
return authed ? <App /> : <Login onLogin={handleLogin} />;
|
||||
return authed ? <App/> : <Login onLogin={handleLogin}/>;
|
||||
}
|
||||
|
||||
const container = document.getElementById('root');
|
||||
const root = createRoot(container);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<Root />
|
||||
</React.StrictMode>
|
||||
<React.StrictMode>
|
||||
<Root/>
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user