App.js (1434B)
1 /** 2 * React Starter Kit (https://www.reactstarterkit.com/) 3 * 4 * Copyright © 2014-present Kriasoft, LLC. All rights reserved. 5 * 6 * This source code is licensed under the MIT license found in the 7 * LICENSE.txt file in the root directory of this source tree. 8 */ 9 10 import React, { PropTypes } from 'react'; 11 12 const ContextType = { 13 // Enables critical path CSS rendering 14 // https://github.com/kriasoft/isomorphic-style-loader 15 insertCss: PropTypes.func.isRequired, 16 }; 17 18 /** 19 * The top-level React component setting context (global) variables 20 * that can be accessed from all the child components. 21 * 22 * https://facebook.github.io/react/docs/context.html 23 * 24 * Usage example: 25 * 26 * const context = { 27 * history: createBrowserHistory(), 28 * store: createStore(), 29 * }; 30 * 31 * ReactDOM.render( 32 * <App context={context}> 33 * <Layout> 34 * <LandingPage /> 35 * </Layout> 36 * </App>, 37 * container, 38 * ); 39 */ 40 class App extends React.PureComponent { 41 42 static propTypes = { 43 context: PropTypes.shape(ContextType).isRequired, 44 children: PropTypes.element.isRequired, 45 }; 46 47 static childContextTypes = ContextType; 48 49 getChildContext() { 50 return this.props.context; 51 } 52 53 render() { 54 // NOTE: If you need to add or modify header, footer etc. of the app, 55 // please do that inside the Layout component. 56 return React.Children.only(this.props.children); 57 } 58 59 } 60 61 export default App;