Warning: you might have spelling stroke
Hey! I've got a very simple question (maybe): how should I pass data to my component? Now I can see only 2 solution: props (from App to my component) and redux (mapStateToProps, mapDispatchToProps) (let's skip ContextAPI for now)
Case #1 (props (from app to my component))
For example, I've got a goods list on my site. Then my list have to recieve data to render it. I should pass it through App, Main, SomeWrapper, SomeOtherWrapper, GoodsList (for example), do not make a mistake and only after that render all goods. Now, let's imagine that I need to add onCLick to GoodsItem => I need to pass onGoodsItemClick through all components, fix all tests (because PropTypes will warn) and PropTypes. It's a little complicated, routine and not very technological, isn't it?
Case 2 (redux (pass through only requirement props with mapStateToProps, mapDispatchToProps))
Okey, let's have a look on second case: sorting component. I've written connect functions for my component. They are looking like these:
const mapStateToProps = (state, ownProps) => ({
...ownProps,
sortType: state.sortType,
allOffers: state.allOffers // allOffers imports only for mapDispatchToProps
});
const mapDispatchToProps = (dispatch) => ({
onSortChange: (allOffers, sortType) => {
dispatch(ActionCreator.changeSortType(sortType));
dispatch(ActionCreator.sortOffers(allOffers, sortType)); // allOffers is using only here
}
});
Here I have to receive allOffers only to give it for mapDispatchToProps for sort function (maybe mistake is here. As I know, ActionCreator has no access to store and have to work only with args). Why should I receive data, which will not even render on the page?
What do React developers do in such a situation? Use only one method? Use both in different cases? Combine this two methods with revisions? Use third method?