Reputation: 1193
I have the following component:
const CompA = () => {
const user = useSelector(state => state.user);
// ... the rest
return (
<div>
<CompB />
</div>
);
}
This component uses the user
data from Redux
store. And I also have the CompB
component that is a child of the CompA
component, this component uses the user
data from Redux
store, too. There are two ways for the CompB
to get the data:
props
or context
.Redux
store by using useSelector
hook (like its parent).I'm struggling to choose one from those approaches. Which one is better and why? Thank you.
Upvotes: 1
Views: 48
Reputation: 478
If <CompB />
is a dump component and he shouldn't know anything about enviroment and business logic the best option would be to do it with props
. Otherwise, use useSelector
in <CompB />
.
Upvotes: 1