DEV Community

Discussion on: Passing Data Between React Components

Collapse
mizaelpv profile image
Mizael Paredes Vielma • Edited

Prop drilling it could be a real problem, that’s why react team built Context, basically with this hook you can access to any data in your store from anywhere in your app

Collapse
zaklaughton profile image
Zak Laughton

I'd argue this example is nowhere near needing React context.

I usually hear "prop drilling" refer to excessively and deeply passing props, which I don't think is happening in this example. Passing props is actually preferable to Context here, and in most other use cases. Even if you do want to work around prop drilling, it's best to try applying component composition before reaching for Context, as mentioned in the Context React docs.

Context is useful, but it has trade-offs. It's a workaround; not a default container for all state. It should only be used in specific use cases when you have data you want to access in many parts of your app.