score:27

Accepted answer

you're getting too caught up on children components. you should structure your app so that you have connected components and non-connected components. non-connected components should be stateless, pure functions essentially, that take in all their requirements via props. connected components should use the connect function to map redux state to props and redux dispatcher to props, and then be responsible for passing those props to child components.

you might have lots of connected components in an app, and lots of non-connected components. this post (by the creator of redux) discusses it in more detail, and talks about non-connected (dumb) components being responsible for actual display of ui, and connected (smart) components being responsible for composing non-connected components.

an example might be (using some newer syntax):

class image extends react {
  render() {
    return (
      <div>
        <h1>{this.props.name}</h1>
        <img src={this.props.src} />
        <button onclick={this.props.onclick}>click me</button>
      </div>
    );
  }
}

class imagelist extends react {
  render() {
    return (
      this.props.images.map(i => <image name={i.name} src={i.src} onclick={this.props.updateimage} />)
    );
  }
}

const mapstatetoprops = (state) => {
  return {
    images: state.images,
  };
};
const mapdispatchtoprops = (dispatch) => {
  return {
    updateimage: () => dispatch(updateimageaction()),
  };
};
export default connect(mapstatetoprops, mapdispatchtoprops)(imagelist);

in this example, imagelist is a connected component and image is a non-connected component.

score:0

there used to be advice to the effect to try to limit the components that you connect. see for example:

https://github.com/reactjs/redux/issues/419

https://github.com/reactjs/redux/issues/419#issuecomment-178850728

anyway, that's really more useful for delegating a slice of state to a component. you can do that if it makes sense for your situation, or if you don't want to pass down a callback that calls dispatch() you can pass the store or dispatch down the hierarchy if you want.


Related Query

More Query from same tag