Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a53f373

Browse files
update context solution
1 parent dc2909c commit a53f373

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import React from "react";
2-
// import { ThemeContext } from "./ThemeContext";
2+
import { useTheme } from "./ThemeProvider";
33
import Button from "./Button";
44
import Hero from "./Hero";
55

6-
/*
7-
TODO: implement a Consumer from your ThemeContext.
8-
with this consumer you can pass the function to toggle
9-
the theme to this button in the `onClick` prop.
10-
*/
6+
// TODO 4, use the useTheme and pass the toggleTheme to the onClick prop of the Button component
117

12-
const App = () => (
13-
<Hero>
14-
<Button>Theme Switcher</Button>
15-
</Hero>
16-
);
8+
const App = () => {
9+
return (
10+
<Hero>
11+
<Button onClick={() => {}}>Theme Switcher</Button>
12+
</Hero>
13+
);
14+
};
1715

1816
export default App;

‎src/components/patterns/Context/exercise/components/Button.jsx‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ const StyledButton = styled.button`
1010
background-color: black;
1111
`;
1212

13-
const Button = ({ children, ...rest }) => {
14-
// TODO 4, use the useTheme in the Button.jsx component in this folder
15-
const { toggleTheme } = () => console.log("BUTTON CLICKED!");
16-
17-
return (
18-
<StyledButton onClick={toggleTheme} {...rest}>
19-
{children}
20-
</StyledButton>
21-
);
22-
};
13+
const Button = ({ onClick, children, ...rest }) => (
14+
<StyledButton onClick={onClick} {...rest}>
15+
{children}
16+
</StyledButton>
17+
);
2318

2419
export default Button;

‎src/components/patterns/Context/exercise/components/ThemeProvider.jsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export const ThemeProvider = ({ children }) => {
1515
// TODO 3, implement the useTheme and share the context like the example useModal
1616
export const useTheme = () => {};
1717

18-
// TODO 4, use the useTheme in the Button.jsx component in this folder
18+
// TODO 4, use the useTheme in the App.jsx component in this folder
1919

2020
export default ThemeProvider;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /