I was going through ReactJS docs. On the page explaining Contexts, I came across following:
If you only want to avoid passing some props through many levels, component composition is often a simpler solution than context.
For example, consider aPage
component that passes auser
andavatarSize
prop several levels down so that deeply nestedLink
andAvatar
components can read it:<Page user={user} avatarSize={avatarSize} /> // ... which renders ... <PageLayout user={user} avatarSize={avatarSize} /> // ... which renders ... <NavigationBar user={user} avatarSize={avatarSize} /> // ... which renders ... <Link href={user.permalink}> <Avatar user={user} size={avatarSize} /> </Link>
In above code, we are still passing user
and avatarSize
as props right? Then how it allows to "avoid passing some props through many levels" as stated in the first sentence of the above quote?