Trí Phan
Trí Phan

Reputation: 1193

Component gets data from its parent or directly from Redux store

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:

I'm struggling to choose one from those approaches. Which one is better and why? Thank you.

Upvotes: 1

Views: 48

Answers (1)

aopanasenko
aopanasenko

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

Related Questions