I should use the same useSelector in each child component or I should pass the useSelector via props?
Both examples below works, I just want to know what is the best practice.
Example passing via props:
const FatherComponent = () => {
const userId = useSelector((state) => state.user.id);
return (
<ChildComponent userId={userId} />
)
}
const ChildComponent = ({userId}) => {
return (
<>{userId}</>
)
}
or example repeating the useSelector:
const FatherComponent = () => {
const userId = useSelector((state) => state.user.id);
return (
<ChildComponent />
)
}
const ChildComponent = () => {
const userId = useSelector((state) => state.user.id);
return (
<>{userId}</>
)
}