Listing 17-5: Using the Context.Consumer Component
import React from 'react';
import {PrefsContext} from './contexts/UserPrefs';
class TimeDisplay extends React.Component {
render() {
return (
<PrefsContext.Consumer>
{userPrefs => {
Your language preference is {userPrefs.lang}.<br />
Your timezone is {userPrefs.timezone}.
}};
</ PrefsContext.Consumer >
)
}
}
export default TimeDisplay;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.