Created
April 6, 2020 14:46
-
-
Save DennisDurairaj/cce3de271a573157b4c3c41a2cb0fa17 to your computer and use it in GitHub Desktop.
This file contains 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 { useSelector } from 'react-redux'; | |
export const Users = (props) => { | |
const users = useSelector((state, ownProps) => state.users[ownProps.id]); //invalid! ownProps does not exist! | |
return <div>{users.map(user => <p>user.name</p>)}</div> | |
}; | |
// It's connect() equivalent | |
import React from 'react'; | |
import { connect } from 'react-redux'; | |
class Users extends React.Component { | |
render() { | |
return ( | |
<div>{this.props.users.map(user => <p>user.name</p>)}</div> | |
) | |
} | |
const mapStateToProps = (state, ownProps) => { | |
users = state.users[ownProps.id]; | |
} | |
export default connect(mapStateToProps, null)(Users); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment