@@ -2,19 +2,15 @@ import React, { useEffect, useState } from 'react';
2
2
import logo from '@/assets/images/logo.png' ;
3
3
import { Link , useNavigate } from 'react-router-dom' ;
4
4
import courses from '@/data/courseData' ;
5
+ import { useTheme } from '@/context/ThemeContext' ;
6
+
5
7
6
8
function Navbar ( { loggedin } ) {
7
9
const [ searchTerm , setSearchTerm ] = useState ( '' ) ;
8
10
const [ suggestions , setSuggestions ] = useState ( [ ] ) ;
9
- const [ theme , setTheme ] = useState ( 'light' ) ;
11
+ const { theme, toggleTheme } = useTheme ( ) ;
10
12
const navigate = useNavigate ( ) ;
11
13
12
- const toggleTheme = ( ) => {
13
- const newTheme = theme === 'light' ? 'dark' : 'light' ;
14
- setTheme ( newTheme ) ;
15
- document . body . setAttribute ( 'data-bs-theme' , newTheme )
16
- } ;
17
-
18
14
const handleSearchChange = ( event ) => {
19
15
const searchInput = event . target . value ;
20
16
setSearchTerm ( searchInput ) ;
@@ -45,11 +41,6 @@ function Navbar({ loggedin }) {
45
41
setSuggestions ( [ ] ) ;
46
42
} ;
47
43
48
- useEffect ( ( ) => {
49
- document . body . setAttribute ( 'data-bs-theme' , theme ) ;
50
- } , [ ] ) ;
51
-
52
-
53
44
return (
54
45
< nav className = { `navbar navbar-expand-lg sticky-top bg-body-tertiary navbar-${ theme } ` } >
55
46
< div className = "container-fluid" >
0 commit comments