Read: Class 33 Context API - 401-advanced-javascript-muna/amman-javascript-401d1 GitHub Wiki
Context API
Context
Context provides a means of passing state down the component tree through a Provider/Consumer relationship.
At as high a level as makes sense, a “provider” can make it’s state available, along with means of altering it (methods).
`import React from 'react';
export const SettingsContext = React.createContext();
class SettingsProvider extends React.Component { constructor(props) { super(props); this.state = { changeTitleTo: this.changeTitleTo, title: 'My Amazing Website', }; }
changeTitleTo = title => { this.setState({ title }); };
render() { return ( <SettingsContext.Provider value={this.state}> {this.props.children} </SettingsContext.Provider> ); } }
export default SettingsProvider;`