Design Patterns · Junior · Question 38 of 75
Which pattern do React Context and <Provider> implement?
- ✓Correct answer: Provider: a value becomes available to the whole subtree without passing props
- 2Singleton: a context can be created only once per app
- 3Builder: a context is assembled step by step from several providers
Explanation
A provider solves prop drilling: the theme, current user and i18n are available to any descendant. There can be any number of contexts, and the same context can be provided with different values in different parts of the tree.