-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
62 lines (57 loc) · 1.57 KB
/
App.js
File metadata and controls
62 lines (57 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import './App.css';
import Navbar from './components/Navbar';
import TextForm from './components/TextForm';
import About from './components/About';
import React, { useState } from 'react';
import Alert from './components/Alert';
import {
BrowserRouter as Router,
Switch,
Route
} from "react-router-dom";
function App() {
const [mode, setMode] = useState('light'); // Whether dark mode is enabled or not
const [alert, setAlert] = useState(null);
const showAlert = (message, type)=>{
setAlert({
msg: message,
type: type
})
setTimeout(() => {
setAlert(null);
}, 1500);
}
const toggleMode = ()=>{
if(mode === 'light'){
setMode('dark');
document.body.style.backgroundColor = '#042743';
showAlert("Dark mode has been enabled", "success");
}
else{
setMode('light');
document.body.style.backgroundColor = 'white';
showAlert("Light mode has been enabled", "success");
}
}
return (
<>
<Router>
<Navbar title="TextUtils" mode={mode} toggleMode={toggleMode} key={new Date()} />
<Alert alert={alert}/>
<div className="container my-3">
<Switch>
{/* /users --> Component 1
/users/home --> Component 2 */}
<Route exact path="/about">
<About mode={mode} />
</Route>
<Route exact path="/">
<TextForm showAlert={showAlert} heading="Try TextUtils - word counter, character counter, remove extra spaces" mode={mode}/>
</Route>
</Switch>
</div>
</Router>
</>
);
}
export default App;