21. When creating an API for context consumers via useContext, what’s the argument you have to provide to the useContext call?

  • The Context.Provider component.
  • The Context object obtained via the createContext call.
  • The React state that defines the global state to be injected.

22. Imagine the below component structure, where all components ComponentA, ComponentB and ComponentC are simple presentational components that hold no props or state:

const App = () => {
< AppContext.Provider>
< ComponentA />
< /AppContext.Provider>

const ComponentA = React.memo(() => < ComponentB />);
const ComponentB = () => < ComponentC / >;
const ComponentC = () => null;

If the App component re-rendered for whatever reason, what would be the sequence of component re-renders that would take place?

  • App -> ComponentA -> ComponentB -> ComponentC.
  • App -> ComponentB -> ComponentC
  • App

23. Even though props and state are inherently different, what are areas where they overlap? Select all that apply.

  • Both props and state are plain JS objects.
  • Both props and state changes trigger a render update.
  • Both props and state are deterministic, meaning that your component always generates the same output for the same combination of props and state.

24. When defining a JavaScript object as a piece of local React state that will be injected as context, what is the specific React hook that allows you to keep the same object reference in memory and prevent unnecessary re-renders if the object itself hasn’t changed any values?

  • useCallback
  • useMemo
  • useRef

25. What are some possible examples of application features that are well suited to be defined as React context? Select all that apply

  • The application theme.
  • Locale preferences.
  • The current authenticated user.
  • The value of a text input.

Leave a Reply