Skip to content

Commit f6ff6dc

Browse files
committed
docs: document ThemeProvider override functionality
1 parent f398686 commit f6ff6dc

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

sections/api/primary/theme-provider.mdx

+25-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ Check the section on [Theming](/docs/advanced#theming).
1313
<Code>theme</Code>
1414
</Column>
1515
<Column>
16-
An object that will be injected as <Code>theme</Code> into all
16+
An object (or function returning an object) that will be injected as <Code>theme</Code> into all
1717
interpolations in styled components beneath the provider.
1818
</Column>
1919
</Row>
2020
</Table>
2121

22+
Simple usage:
23+
2224
```react
2325
// import styled, { ThemeProvider } from 'styled-components'
2426
@@ -32,3 +34,25 @@ render(
3234
</ThemeProvider>
3335
)
3436
```
37+
38+
Adding to or replacing an outer theme using nested `ThemeProvider`:
39+
40+
```react
41+
// import styled, { ThemeProvider } from 'styled-components'
42+
43+
const Box = styled.div`
44+
background-color: ${props => props.theme.bg};
45+
color: ${props => props.theme.color};
46+
`
47+
48+
render(
49+
<ThemeProvider theme={{ bg: 'white', color: 'mediumseagreen' }}>
50+
<Box>
51+
I'm mediumseagreen with a white background!
52+
<ThemeProvider theme={outerTheme => ({...outerTheme, bg: 'black'})}>
53+
<Box>I'm mediumseagreen with a black background!</Box>
54+
</ThemeProvider>
55+
</Box>
56+
</ThemeProvider>
57+
)
58+
```

0 commit comments

Comments
 (0)