Skip to content

Instantly share code, notes, and snippets.

@psychicbologna
Created September 12, 2019 10:37
Show Gist options
  • Save psychicbologna/bf3c830401012c8bd6b1573f51d4e8cf to your computer and use it in GitHub Desktop.
Save psychicbologna/bf3c830401012c8bd6b1573f51d4e8cf to your computer and use it in GitHub Desktop.
-What situations would be good to use context?
Data that would be considered 'global' in a React component tree, such as user information, preferred language, theme or permissions.
-If you need to pass a prop down 1 or 2 levels, is context necessary?
Context is only necessary when multiple components at different levels of the tree require access to it. Compponent composition may be a more elegant solution.
-Can you pass a component instance as a prop to avoid the need for context?
You may. This technique is called inversion of control and is useful in cases where context from one component is only needed by something a few levels down, not on any more levels between.
-Can you write your own components that accept render props?
Yes. We can do this primarily by using context and Consumer, which allows values to be passed into elements by accepting them as arguments in their render props.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment