Ну, не уверен, если оценивает решение, но с HO C (пользовательский метод с DynamicProps), похоже, работает:
import React from "react";
function withDynamicProps(Component, initalProps = {}) {
return class extends React.Component {
constructor(props) {
super(props);
this.state = initalProps;
this.setDynamicProps = this.setDynamicProps.bind(this);
}
setDynamicProps(dynamicProp) {
this.setState(dynamicProp);
}
render() {
return (
<Component
{...this.props}
{...this.state}
setDynamicProps={this.setDynamicProps}
/>
);
}
};
}
export { withDynamicProps };
и в моем контейнере -компонент:
class ContainerComponent extends Component {
....
componentDidMount() {
const { countryId } = this.props;
loadCountries();
if (countryId) {
loadRegions(countryId);
}
}
componentDidUpdate(prevProps, prevState) {
const { prevState} = this.props;
if (countryId && prevState.countryId !== countryId) {
loadRegions(countryId);
}
}
onCountryChangeHandler(countryId) {
this.props.setDynamicProps({ countryId });
}
render() {
const { countriesList, regionsList, countryId } = this.props;
return (
<PresentationComponent {...this.props}/>
);
}
}
const mapStateToProps = (state, ownProps) => {
const {
countryId
} = ownProps;
const {
entities: { countries, regions },
associativitiesRefs: { regionsByCountry }
} = state;
const countriesList = Object.keys(countries).map(x =>
denormalize(countries[x], Schemas.COUNTRY, state.entities)
);
const regionsIdByCountry = regionsByCountry[countryId] || {
ids: []
};
const regionsList = regionsIdByCountry.ids.map(x =>
denormalize(regions[x], Schemas.REGION, state.entities)
);
return {
countriesList,
regionsList
};
};
export default withDynamicProps(
withRouter(
connect(
mapStateToProps,
{
loadCountries,
loadRegions
}
)(ContainerComponent)
)
);