Browse Source

Update highlights

main
Alex Krolick 7 years ago
parent
commit
9f5499789a
  1. 1
      examples/context/forwarding-refs.js
  2. 2
      examples/context/lifecycles.js
  3. 16
      examples/context/motivation-solution.js
  4. 5
      examples/context/multiple-contexts.js

1
examples/context/forwarding-refs.js

@ -4,6 +4,7 @@ const Button = ({theme, children}) => (
</button> </button>
); );
// highlight-range{1,3}
export default React.forwardRef((props, ref) => ( export default React.forwardRef((props, ref) => (
<ThemeContext.Consumer> <ThemeContext.Consumer>
{theme => <Button {...props} theme={theme} ref={ref} />} {theme => <Button {...props} theme={theme} ref={ref} />}

2
examples/context/lifecycles.js

@ -1,5 +1,6 @@
class Button extends React.Component { class Button extends React.Component {
componentDidMount() { componentDidMount() {
// highlight-next-line
alert(this.props.theme); alert(this.props.theme);
} }
@ -13,6 +14,7 @@ class Button extends React.Component {
} }
} }
// highlight-range{3}
export default props => ( export default props => (
<ThemeContext.Consumer> <ThemeContext.Consumer>
{theme => <Button {...props} theme={theme} />} {theme => <Button {...props} theme={theme} />}

16
examples/context/motivation-solution.js

@ -2,13 +2,15 @@
// highlight-next-line // highlight-next-line
const ThemeContext = React.createContext('light'); const ThemeContext = React.createContext('light');
// highlight-range{1,3-5} const ThemedButton = props => {
// The ThemedButton receives the theme from context // highlight-range{1,3-5}
const ThemedButton = props => ( // The ThemedButton receives the theme from context
<ThemeContext.Consumer> return (
{theme => <Button theme={theme} />} <ThemeContext.Consumer>
</ThemeContext.Consumer> {theme => <Button theme={theme} />}
); </ThemeContext.Consumer>
);
};
// An intermediate component // An intermediate component
const Toolbar = props => { const Toolbar = props => {

5
examples/context/multiple-contexts.js

@ -1,7 +1,9 @@
// Create a theme context, defaulting to light theme // Theme context, default to light theme
// highlight-next-line
const ThemeContext = React.createContext('light'); const ThemeContext = React.createContext('light');
// Signed-in user context // Signed-in user context
// highlight-next-line
const UserContext = React.createContext(); const UserContext = React.createContext();
class App extends React.Component { class App extends React.Component {
@ -15,6 +17,7 @@ class App extends React.Component {
}; };
render() { render() {
// highlight-range{9}
return ( return (
<ThemeContext.Provider value={this.props.theme}> <ThemeContext.Provider value={this.props.theme}>
<UserContext.Provider <UserContext.Provider

Loading…
Cancel
Save