react-redux-starter-kit
react-redux-starter-kit copied to clipboard
How do I inject a store into a reusable component?
I have a Header component in the reusable component directory that I need to bind props into. I've added a container to the reusable container directory but it doesn't seem to be binding my props.
My directory structure looks like this: src |-components |----Header |--------Header.js |-containers |----HeaderContainer.js
So I'm not sure what the point of the "containers" directory is at this point, my HeaderContainer.js file was being ignored. I ended up putting the connect code in the header component itself which got me to where I needed to be.
class _Header extends Component {
. . .
}
const mapStateToProps = (state) => ({
userDetails: state.userDetails
})
const Header = connect(mapStateToProps, {setUserDetails})(_Header);
export default Header;
That's hardly a good solution, you can just pass your desired props from the top container, which I assume already has the props binded, it should look like so:
<Header details={props.details} />
Seeing how you pass a explicit value userDetails to connect, made me think that this Header can be hardly reusable, as it only seems to do a very explicit role, which is to render userDetails..