Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to store in a sub component #36

Open
timhc22 opened this issue Feb 4, 2023 · 1 comment
Open

Connecting to store in a sub component #36

timhc22 opened this issue Feb 4, 2023 · 1 comment

Comments

@timhc22
Copy link

timhc22 commented Feb 4, 2023

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);
@pourya7
Copy link
Owner

pourya7 commented Feb 15, 2023

Hi @timhc22, Thanks for the idea and also the PR.
It's been quite some times that I haven't coded React, so I wont be able to give any opinion on this.
You're more than welcome to take over the project, if you are interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants