Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
React current user Context or Composition

So I'm trying to understand the best practice use-cases of React Context API vs the standard Composition pattern.

One of the edge-cases, in my opinion, would be an authenticated user that the App uses its data (e.g. User: {name: string, pass: string, posts: Array<>, ...}) throughout the code (in different components).

I tried deciphering what React Docs has to say about it, but it's kinda awkward because it seem to be sort of self-contradictory.

In the beginning the Docs gives a couple of examples for Context usage:

Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.

But then it goes to say that in many cases Composition would be enough, and the given example is about a current user:

For example, consider a Page component that passes a user and avatarSize prop several levels down so that deeply nested Link and Avatar components can read it... One way to solve this issue without context is to pass down the Avatar component itself so that the intermediate components don’t need to know about the user or avatarSize props

So essentially after saying that Context would be good for user data handling, the Docs gives an example using Composition.

I'm not trying to nit-pick on, or mock the Docs, definitely not my intent. What I'm trying to understand is, since obviously both ways are applicable, what is the best practice for user data handling throughout the App? Are there any considerations I should take when choosing between those two methods, aside from comfortability? I see that in the Docs it says about Context:

Apply it sparingly because it makes component reuse more difficult

How so, especially in this case? I can understand it in cases where you don't know what data your component would require (and hence the use of props.children), but that isn't such a case.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda