0
0
Reactframework~10 mins

Consuming context in React - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to consume context using the correct hook.

React
const value = React.[1](MyContext);
Drag options to blanks, or click blank then click option'
AuseState
BuseEffect
CuseContext
DuseRef
Attempts:
3 left
💡 Hint
Common Mistakes
Using useState or useEffect instead of useContext.
Trying to access context without a hook.
2fill in blank
medium

Complete the code to import the hook needed to consume context.

React
import React, { [1] } from 'react';
Drag options to blanks, or click blank then click option'
AuseEffect
BuseContext
CuseState
DuseMemo
Attempts:
3 left
💡 Hint
Common Mistakes
Importing useState or useEffect instead of useContext.
Forgetting to import the hook.
3fill in blank
hard

Fix the error in consuming context by filling the blank with the correct context variable.

React
const theme = useContext([1]);
Drag options to blanks, or click blank then click option'
AThemeContext
BThemeProvider
Ctheme
DuseTheme
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the provider component instead of the context object.
Passing a hook name or variable instead of the context.
4fill in blank
hard

Fill both blanks to consume context and display its value.

React
const value = [1]([2]);
return <div>{value}</div>;
Drag options to blanks, or click blank then click option'
AuseContext
BuseState
CMyContext
DThemeProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using useState instead of useContext.
Passing the provider instead of the context object.
5fill in blank
hard

Fill all three blanks to consume context and use it in a component.

React
import React, { [1] } from 'react';

function MyComponent() {
  const value = [2]([3]);
  return <p>{value}</p>;
}
Drag options to blanks, or click blank then click option'
AuseContext
BuseState
CMyContext
DThemeProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Importing or using the wrong hook.
Passing the provider or other variables instead of the context object.