Skip to content

Commit 39df2ae

Browse files
committed
Changes
1 parent f175e56 commit 39df2ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+619
-116
lines changed

app/ThemeProvider.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// React
2+
import React, { createContext, useState, useContext } from 'react';
3+
4+
// Create a context for the theme
5+
const ThemeContext = createContext();
6+
7+
// Create a provider that will hold the state and enable it to be modified
8+
export const ThemeProvider = ({ children }) => {
9+
const [theme, setTheme] = useState('light');
10+
11+
const toggleTheme = () => {
12+
setTheme((prevTheme) => (prevTheme === 'light' ? 'dark' : 'light'));
13+
};
14+
15+
return (
16+
<ThemeContext.Provider value={{ theme, toggleTheme }}>
17+
{children}
18+
</ThemeContext.Provider>
19+
);
20+
};
21+
22+
// Create a custom hook that will allow our components to easily access and modify the theme
23+
export const useTheme = () => useContext(ThemeContext);
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)