I completely lost the concept of a reaction-reduction container (i.e. a connector) as it does not do what I expected. My problem is straightforward, and reasonable for me, but I cannot find a well-written example of how to accomplish it.
Say we have a response component that connects to the repository with the product context, and we will call this component ProductContext.
Also, suppose we want to reuse ProductContextliberally throughout the application in order to avoid the boilerplate code for dispatching actions on all other components that may need products.
Illustratively, this is what I mean:
from DiscountuedProducts:
<ProductContext >
// do something with props from container
</ProductContext >
from SeasonalProducts:
<ProductContext >
// do something with props from container
</ProductContext >
, -, , , . ?
ProductContextComponent:
<section >
<DiscontinuedProducts />
<SeasonalProducts />
</section >
, , " ", , , .
, ProductContext:
@connect(state => ({
products: state.productsReducer.products
}))
export default class ProductContext extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
const { dispatch } = this.props;
const clientId = this.context.clientInfo._id;
dispatch(fetchProductsIfNeeded(clientId));
}
static contextTypes = {
clientInfo: PropTypes.object.isRequired
};
static propTypes = {
children: PropTypes.node.isRequired,
dispatch: PropTypes.func.isRequired,
products: PropTypes.array
};
render() {
if (!this.props.products) return <Plugins.Loading />;
.....
return (
// I want to put the products array here
);
}
};
, :
DiscountuedProducts:
<ProductContext >
// do something with props from container
</ProductContext >
DiscontinuedProducts , .
? ?
- , , , , . -.
: HOC.
user1177440