react-without-redux
react-without-redux copied to clipboard
Connecting to store in a sub component
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);
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.