This question is specifically about the newer react redux hooks, particularly useSelector and useDispatch. Say you have one component that is a list and another component that is a list item. The list component contains a list of the list items.
You need to use a piece of the redux store in the list item and dispatch an action also in the list item. The data that you need from the store and the dispatch function will be the same for each item in the list.
Should you use those hooks in the items themselves or use the hooks in the parent list component and pass the store and dispatch function down to the items via props? Does it have some performance impact to do the useDispatch and useSelector hook on each item in the list?
Edit to add code example:
const List = () => (
<div>
{someArray.map((item) => {
return (
<ListItem/>
);
})}
</div>
);
const ListItem = () => {
const myState = useSelector((state) => state);
const dispatch = useDispatch();
// Do these here or in the parent and pass down as props?
return (
<div />
);
};