Skip to content

Instantly share code, notes, and snippets.

@DennisDurairaj
Created April 6, 2020 14:46
Show Gist options
  • Save DennisDurairaj/cce3de271a573157b4c3c41a2cb0fa17 to your computer and use it in GitHub Desktop.
Save DennisDurairaj/cce3de271a573157b4c3c41a2cb0fa17 to your computer and use it in GitHub Desktop.
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