React-Context Flashcards
What is the purpose of React “context”?
Context lets the parent component make some information available to any component in the tree below it—no matter how deep—without passing it explicitly through props.
What values can be stored in context?
but you could pass any kind of value (even an object)
How do you create context and make it available to the components?
you assign the createContext() function to a variable and pass it a default value and then to make it available to a component, you have to use the useContext hook and pass it the variable with createContext() assigned to it.
How do you access the context values?
You have to wrap the components with a context provider. This tells react that if any component inside the parent component asks for the context, give them this level.” The component will use the value of the nearest <LevelContext.Provider> in the UI tree above it.</LevelContext.Provider>
When would you use context? (in addition to the best answer: “rarely”)
When you have a compontent nested deep inside a component tree that you want to provide specific values to without having to pass the value down as a prop through many components