Skip to content

Connecting to store in a sub component #36

@timhc22

Description

@timhc22

Hello, I would have opened this in discussions, but it is not enabled, so it is less of an 'issue' and more of a 'discussion'

https://stackoverflow.com/questions/62555916/how-to-pass-store-to-the-sub-component-in-react-redux
https://stackoverflow.com/questions/52857738/mapstatetoprops-for-functional-component

Any idea how to use this in a sub component, from the above links, I could have done something like this in react-redux. Still learning how to use these methods here!

import { connect } from 'react-redux';

class MyComponent extends React.Component {

    constructor(props) {
        super(props);
        console.log(this.props.name);
    }
    ...
}

const mapStateToProps = (store) => {
   // console.log('store', store);
   return {
      name: store.<reducer>.name,
   };
};

export default connect(mapStateToProps, null)(MyComponent);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions