diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-06-26 22:25:55 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-06-26 22:25:55 +0200 |
commit | dedf8025a547d698d9f2e62f0897493d61ffadd5 (patch) | |
tree | bb1736fad1f20294c0ce9b53d6d33c07e7d1dcfe /src/client/react/components/page | |
parent | 315adeb5e2012b7f7bcfcd1478f9d6dd2cc1092d (diff) |
Use mapStateToProps for router simplification
Diffstat (limited to 'src/client/react/components/page')
-rw-r--r-- | src/client/react/components/page/User.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/client/react/components/page/User.js b/src/client/react/components/page/User.js index 4b9af64..af14188 100644 --- a/src/client/react/components/page/User.js +++ b/src/client/react/components/page/User.js @@ -20,6 +20,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; import { Redirect } from 'react-router-dom'; import { Elevation } from 'rmwc/Elevation'; import Search from '../container/Search'; @@ -33,12 +34,15 @@ import './User.scss'; class UserPage extends React.Component { static propTypes = { // react-router - match: PropTypes.object.isRequired, + user: PropTypes.string, }; + static defaultProps = { + user: null, + } + render() { - const { match } = this.props; - const user = userFromMatch(match); + const { user } = this.props; if (!user) { // Invalid user, redirect to index. @@ -66,4 +70,8 @@ class UserPage extends React.Component { } } -export default UserPage; +const mapStateToProps = (state, { match }) => ({ + user: userFromMatch(match), +}); + +export default connect(mapStateToProps)(UserPage); |