Created
May 15, 2020 01:59
-
-
Save mzibari/3fea5d32c0a678b32d696d5f29df659c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What situations would be good to use context? | |
When more than one component in a deeply nested tree need to access some data in our app, conext will be a good choice. | |
If you need to pass a prop down 1 or 2 levels, is context necessary? | |
No, it's not necessary. Applying context makes component's reuse more difficult. | |
Can you pass a component instance as a prop to avoid the need for context? | |
Yes you can, this is what's called component composition. | |
Can you write your own components that accept render props? | |
Yes I can | |
No seriously | |
We can use Context.Consumer to do that | |
const colorContext = React.createContext ({ | |
color: 'blue' | |
}); | |
export default colorContext; | |
import colorContext from './...... | |
. | |
. | |
. | |
<colorContext.Consumer> | |
{function renderProp() { | |
<div /> | |
} | |
</colorContext.Consumer> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment