react-without-redux icon indicating copy to clipboard operation
react-without-redux copied to clipboard

Connecting to store in a sub component

Open timhc22 opened this issue 2 years ago • 1 comments

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);

timhc22 avatar Feb 04 '23 01:02 timhc22

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.

pourya7 avatar Feb 15 '23 18:02 pourya7