← React Beginner Questions - Set 10 Q91

What is the purpose of the useContext hook?

React Beginner Questions - Set 10

Example

const CartContext = createContext({ items: [] });

function Badge() {
  const { items } = useContext(CartContext);
  return <span>{items.length}</span>;
}

What to notice

← Back to the question list