AllenYuan

router - app refactor

Apr 24th, 2020
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Child components
  2. import Header from './Header';
  3.  
  4. // modules for a redux-connected React component
  5. import React from 'react';
  6. import { connect } from 'react-redux';
  7.  
  8. // extract appName from state
  9. const mapStateToProps = state => ({
  10.   appName: state.appName
  11. });
  12.  
  13. // render the appname
  14. class App extends React.Component {
  15.   render() {
  16.     return (
  17.       // render Header and children from router below that
  18.       <div>
  19.         <Header appName={this.props.appName} />
  20.         {this.props.children}
  21.       </div>
  22.     );
  23.   }
  24. }
  25.  
  26. // ensure react-router attaches children to this component's props
  27. App.contextTypes = {
  28.   router: React.PropTypes.object.isRequired
  29. };
  30.  
  31. // export redux-connected App
  32. export default connect(mapStateToProps, () => ({}))(App);
Advertisement
Add Comment
Please, Sign In to add comment