I'm sorry if this comes across the wrong way. I understand the concept of contexts. What I don't quite understand is this example when to not use them.
function Page(props) {
const user = props.user;
const userLink = (
<Link href={user.permalink}>
<Avatar user={user} size={props.avatarSize} />
</Link>
);
return <PageLayout userLink={userLink} />;
}
// Now, we have:
<Page user={user} avatarSize={avatarSize} />
// ... which renders ...
<PageLayout userLink={...} />
// ... which renders ...
<NavigationBar userLink={...} />
// ... which renders ...
{props.userLink}
and claims
This inversion of control can make your code cleaner in many cases by reducing the amount of props you need to pass through your application and giving more control to the root components.
My gut reaction was the opposite. The Page component now needs to know details of the NavigationBar (it needs to know what elements/components NagivationBar needs. The Page component seems like it should have zero knowledge of what's in the NavigationBar. It should be passing down some opaque hunk of data and letting NavigationBar deal with it. That it does need to know the details is a strong coupling, not a loose coupling.
Is that a bad example that's trying to illustrated some bigger point but the example is just poorly chosen or am I maybe mis-understanding something?
The text was updated successfully, but these errors were encountered:
greggman
changed the title
context.md example
context.md example, when not to use contexts
Sep 29, 2020
I'm sorry if this comes across the wrong way. I understand the concept of contexts. What I don't quite understand is this example when to not use them.
It shows this example
Being replaced by this
and claims
My gut reaction was the opposite. The
Pagecomponent now needs to know details of theNavigationBar(it needs to know what elements/componentsNagivationBarneeds. ThePagecomponent seems like it should have zero knowledge of what's in theNavigationBar. It should be passing down some opaque hunk of data and lettingNavigationBardeal with it. That it does need to know the details is a strong coupling, not a loose coupling.Is that a bad example that's trying to illustrated some bigger point but the example is just poorly chosen or am I maybe mis-understanding something?
The text was updated successfully, but these errors were encountered: