Skip to content

Instantly share code, notes, and snippets.

@akinogu
Created October 14, 2021 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinogu/5beabba6d1565f0977d37afe2c16b28d to your computer and use it in GitHub Desktop.
Save akinogu/5beabba6d1565f0977d37afe2c16b28d to your computer and use it in GitHub Desktop.
[styled-components]theme
import { useEffect } from 'react'
import styled from 'styled-components'
import { useTheme } from './util/Theme'
const Text = styled.div`
color: ${p => p.theme.color};
`
const App = () => {
const { setColor } = useTheme()
// APIなどからスタイルを取得した後にsetColorに値を渡す
useEffect(() => setColor('red'), [setColor])
return (
<Text>Theme sample</Text>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment