Medium
You need to implement a custom React context for managing theme preferences. Which implementation correctly handles dynamic theme updates?
1const ThemeContext = createContext();23function ThemeProvider({ children, initialTheme = 'light' }) {4 // Missing theme management logic here56 return (7 <ThemeContext.Provider value={value}>8 {children}9 </ThemeContext.Provider>10 );11}1213function useTheme() {14 const context = useContext(ThemeContext);15 if (!context) {16 throw new Error('useTheme must be used within ThemeProvider');17 }18 return context;19}2021export { ThemeProvider, useTheme };