|
1 |
| -import React, { Component } from 'react'; |
| 1 | +import React from 'react'; |
2 | 2 | import { MemoryRouter as Router, Route, NavLink } from 'react-router-dom';
|
| 3 | +import PropTypes from 'prop-types'; |
3 | 4 | import Tree from '../components/Tree';
|
4 | 5 | import Chart from '../components/Chart';
|
5 | 6 |
|
6 |
| -class StateContainer extends Component { |
7 |
| - constructor(props) { |
8 |
| - super(props); |
9 |
| - } |
| 7 | +const StateContainer = ({ snapshot }) => ( |
| 8 | + <Router> |
| 9 | + <div className="state-container"> |
| 10 | + <div className="navbar"> |
| 11 | + <NavLink className="router-link" activeClassName="is-active" to="/tree"> |
| 12 | + Tree |
| 13 | + </NavLink> |
| 14 | + <NavLink className="router-link" activeClassName="is-active" to="/chart"> |
| 15 | + Chart |
| 16 | + </NavLink> |
| 17 | + </div> |
| 18 | + <Route path="/tree" render={() => <Tree snapshot={snapshot} />} /> |
| 19 | + <Route path="/chart" render={() => <Chart snapshot={snapshot} />} /> |
| 20 | + </div> |
| 21 | + </Router> |
| 22 | +); |
10 | 23 |
|
11 |
| - render() { |
12 |
| - const { snapshot } = this.props; |
13 |
| - return ( |
14 |
| - <Router> |
15 |
| - <div className="state-container"> |
16 |
| - <div className="navbar"> |
17 |
| - <NavLink className="router-link" activeClassName="is-active" to="/tree"> |
18 |
| - Tree |
19 |
| - </NavLink> |
20 |
| - <NavLink className="router-link" activeClassName="is-active" to="/chart"> |
21 |
| - Chart |
22 |
| - </NavLink> |
23 |
| - </div> |
24 |
| - <Route path="/tree" render={() => <Tree snapshot={snapshot} />} /> |
25 |
| - <Route path="/chart" render={() => <Chart snapshot={snapshot} />} /> |
26 |
| - </div> |
27 |
| - </Router> |
28 |
| - ); |
29 |
| - } |
30 |
| -} |
31 |
| -{ |
32 |
| -} |
| 24 | +StateContainer.propTypes = { |
| 25 | + snapshot: PropTypes.shape({ |
| 26 | + state: PropTypes.oneOfType([ |
| 27 | + PropTypes.string, |
| 28 | + PropTypes.object, |
| 29 | + ]), |
| 30 | + children: PropTypes.arrayOf( |
| 31 | + PropTypes.object, |
| 32 | + ), |
| 33 | + }).isRequired, |
| 34 | +}; |
33 | 35 |
|
34 | 36 | export default StateContainer;
|
0 commit comments