Last active
May 12, 2016 01:09
-
-
Save ro-savage/a953c3a6ce01a6e75355dde9a55748c2 to your computer and use it in GitHub Desktop.
Avoiding PropType warnings due to renders before API data is returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import style from './UserDropDown.scss' | |
| class UserDropDown extends React.Component { | |
| render() { | |
| const { logout, user } = this.props | |
| return ( | |
| <div> | |
| <span onClick={logout}>{user.username}</span> | |
| </div> | |
| ) | |
| } | |
| } | |
| UserDropDown.propTypes = { | |
| logout: React.PropTypes.func.isRequired, | |
| user: React.PropTypes.object.isRequired, | |
| } | |
| export default UserDropDown |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import { connect } from 'react-redux' | |
| import UserDropDown from '../../components/UserDropDown/UserDropDown' | |
| import { getUser } from '../../redux/users/users' | |
| import { getThisUserId, logout } from '../../redux/user-auth/user-auth' | |
| const UserDropDownContainer = (props) => { | |
| return ( | |
| <div> | |
| {props.user ? <UserDropDown {...props} /> : null } | |
| </div> | |
| ) | |
| } | |
| UserDropDownContainer.propTypes = { | |
| user: React.PropTypes.object, | |
| } | |
| const mapStateToProps = (state) => { | |
| const userId = getThisUserId(state) | |
| return { | |
| user: getUser(state, userId), | |
| } | |
| } | |
| const mapDispatchToProps = (dispatch) => ( | |
| { | |
| logout: () => dispatch(logout()), | |
| } | |
| ) | |
| export default connect(mapStateToProps, mapDispatchToProps)(UserDropDownContainer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { connect } from 'react-redux' | |
| import UserDropDown from '../../components/UserDropDown/UserDropDown' | |
| import { getUser } from '../../redux/users/users' | |
| import { getThisUserId, logout } from '../../redux/user-auth/user-auth' | |
| const mapStateToProps = (state) => { | |
| const userId = getThisUserId(state) | |
| return { | |
| user: getUser(state, userId), | |
| } | |
| } | |
| const mapDispatchToProps = (dispatch) => ( | |
| { | |
| logout: () => dispatch(logout()), | |
| } | |
| ) | |
| export default connect(mapStateToProps, mapDispatchToProps)(UserDropDown) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment