-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document class contextType as the primary consuming mechanism (#1283)
* Document class contextType as the primary consuming mechanism * Update context.md
- Loading branch information
1 parent
1601307
commit 896214b
Showing
10 changed files
with
88 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import {ThemeContext} from './theme-context'; | ||
|
||
function ThemedButton(props) { | ||
// highlight-range{2-9} | ||
return ( | ||
<ThemeContext.Consumer> | ||
{theme => ( | ||
<button | ||
{...props} | ||
style={{backgroundColor: theme.background}} | ||
/> | ||
)} | ||
</ThemeContext.Consumer> | ||
); | ||
class ThemedButton extends React.Component { | ||
// highlight-range{3,12} | ||
render() { | ||
let props = this.props; | ||
let theme = this.context; | ||
return ( | ||
<button | ||
{...props} | ||
style={{backgroundColor: theme.background}} | ||
/> | ||
); | ||
} | ||
} | ||
ThemedButton.contextType = ThemeContext; | ||
|
||
export default ThemedButton; |