You are too hung up on children's components. You must structure your application so that you connect components and unrelated components. Non-connected components should be stand-alone, essentially pure functions that accept all their requirements through the requisites. Connected components should use the connect function to display the state of the reduction in the details and the reducer manager in the details, and then be responsible for transferring these details to the child components.
You can have many connected components in an application and many insecure components. This post (the author of the redux) discusses it in more detail and talks about unrelated (dumb) components responsible for the actual display of the user interface and connected (smart) components responsible for compiling unrelated components.
An example would be (using some new 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 an unrelated component.
source share