Week 11 Quiz Questions Flashcards
What is the purpose of React “context”?
allows the parent component to pass down information directly to a child without props
What values can be stored in context?
any type of values, typically objects, but can be functions or other things
How do you create context and make it available to the components?
context created first by importing { createContext } from react and then exporting a variable (if on a diff file) const someContext = createContext()
How do you access the context values?
in the child component, use useContext and pass to it the createContext previously created
you assign to it the property given from the parent component and passed down via the Context.Provider
wrapping the main app.js components in Context.provider
When would you use context? (in addition to the best answer: “rarely”)
when you want to directly pass something down to a child that is far away– this avoids prop drilling which can be a lot of writing code in different layers just to get one thing to a distant child
What is a React custom hook?
custom function that allows you to pass functionality down to other areas
When are custom hooks useful? When are they not required?
useful for organizing functionality
What is the syntax (or naming convention) for writing a custom hook?
useCustomStateName()
How do you call a custom hook?
like any other function (must be imported)
When do custom hooks execute?
on call