Skip to content

Commit 626708b

Browse files
committed
styled-components with ThemeProvider
1 parent 4954463 commit 626708b

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

src/App.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from "react";
22
import Component from './components/Component'
3-
4-
//Provider
5-
import ThemeContext from "./contexts/theme";
3+
import { ThemeProvider } from "styled-components";
64

75
const App = () => {
86
const theme = {
@@ -16,10 +14,12 @@ const App = () => {
1614
};
1715

1816
return (
19-
<ThemeContext.Provider value={{ theme }}>
17+
<ThemeProvider theme={theme}>
2018
<div className="App">
2119
<Component/>
2220
</div>
23-
</ThemeContext.Provider>);
21+
</ThemeProvider>
22+
);
23+
2424
}
2525
export default App;

src/components/Component.jsx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React, { useContext } from "react";
2-
import ThemeContext from "../contexts/theme";
3-
import styled, { ThemeProvider } from "styled-components";
1+
import React from "react";
2+
import styled from "styled-components";
43

54
const Wrapper = styled.div`
65
padding: 40px;
@@ -42,24 +41,20 @@ const Link = styled.a`
4241
`;
4342

4443
const Component = props => {
45-
const { theme } = useContext(ThemeContext);
46-
4744
return (
48-
<ThemeProvider theme={theme}>
49-
<Wrapper>
50-
<Title>Example component CSS</Title>
51-
<Paragraph>
52-
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ducimus,
53-
temporibus labore voluptatibus aspernatur illo ad id sit nulla, a
54-
atque doloribus itaque ab? Soluta, exercitationem illum provident quod
55-
iure numquam?
56-
</Paragraph>
57-
<Button>I'm a button</Button>
58-
<Link href="/#" onClick={e => e.preventDefault()}>
59-
I'm a link
60-
</Link>
61-
</Wrapper>
62-
</ThemeProvider>
45+
<Wrapper>
46+
<Title>Example component CSS</Title>
47+
<Paragraph>
48+
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ducimus,
49+
temporibus labore voluptatibus aspernatur illo ad id sit nulla, a atque
50+
doloribus itaque ab? Soluta, exercitationem illum provident quod iure
51+
numquam?
52+
</Paragraph>
53+
<Button>I'm a button</Button>
54+
<Link href="/#" onClick={e => e.preventDefault()}>
55+
I'm a link
56+
</Link>
57+
</Wrapper>
6358
);
6459
};
6560

src/contexts/theme.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)