Skip to content

Commit a869d92

Browse files
pkodmadjamiebuilds
authored andcommitted
Add another component that accepts context
1 parent d176bf8 commit a869d92

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

examples/theme-example/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//@flow
22
import React from "react";
33
import { render } from "react-dom";
4-
import { ThemeToggler, Title } from "./theme-context";
4+
import { ThemeToggler, Title, Emoji } from "./theme-context";
55

66
const App = () => (
77
<ThemeToggler>
88
<Title>Really cool context</Title>
9+
<Emoji />
910
</ThemeToggler>
1011
);
1112

examples/theme-example/theme-context.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,24 @@ export class Title extends React.Component<{ children: Node }> {
4646
);
4747
}
4848
}
49+
50+
export class Emoji extends React.Component<{ children: Node }> {
51+
render() {
52+
return (
53+
<ThemeContext.Consumer>
54+
{theme => (
55+
<div
56+
style={{
57+
fontSize: "35px",
58+
background: "white",
59+
height: "40px",
60+
width: "40px"
61+
}}
62+
>
63+
{theme === "light" ? "⚡️" : "🕶"}
64+
</div>
65+
)}
66+
</ThemeContext.Consumer>
67+
);
68+
}
69+
}

0 commit comments

Comments
 (0)