Last active
October 14, 2021 12:35
-
-
Save akinogu/f3ebf51594dea3eba5beb48f74c97da6 to your computer and use it in GitHub Desktop.
[styled-components]theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext, useContext, useState } from 'react' | |
import { ThemeProvider as StyledThemeProvider } from 'styled-components' | |
const ThemeContext = createContext({ | |
setColor: (_: string) => {} | |
}) | |
export const ThemeProvider: React.FC = ({ children }) => { | |
// デフォルト値としてblueを指定 | |
const [color, setColor] = useState('blue') | |
return ( | |
// スタイルを上書きするsetterをvalueにわたす | |
<ThemeContext.Provider value={{ setColor }}> | |
<StyledThemeProvider | |
theme={{ color }} | |
> | |
{children} | |
</StyledThemeProvider> | |
</ThemeContext.Provider> | |
) | |
} | |
export const useTheme = () => useContext(ThemeContext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment