{
  "id": "react/context-not-provided",
  "signature": "TypeError: Cannot read properties of undefined (reading 'dispatch'). This error is located at: in ConsumerComponent (at App.js:10)",
  "signature_zh": "类型错误：无法读取 undefined 的属性（读取 'dispatch'）。此错误位于：ConsumerComponent (at App.js:10)",
  "regex": "Cannot read properties of undefined.*reading.*dispatch.*useContext",
  "domain": "react",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A component tries to use useContext to access a context value, but it is not wrapped in the corresponding Provider component, so the context value is undefined.",
  "root_cause_type": "generic",
  "root_cause_zh": "组件尝试使用 useContext 访问上下文值，但它没有被相应的 Provider 组件包裹，因此上下文值为 undefined。",
  "versions": [
    {
      "version": "react@18.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "react-dom@18.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Importing the context directly and trying to use it as a value",
      "why_fails": "The context object itself is not the value; it must be provided via a Provider.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding a default value to createContext but not wrapping in Provider",
      "why_fails": "The default value is only used when there is no Provider at all, but if the component is wrapped in a Provider without a value prop, the context is still undefined.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using useContext inside a class component",
      "why_fails": "useContext is a hook and cannot be used in class components; use Context.Consumer instead.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Wrap the component tree with the Provider: `<MyContext.Provider value={{ dispatch }}><ConsumerComponent /></MyContext.Provider>`",
      "success_rate": 0.95,
      "how": "Wrap the component tree with the Provider: `<MyContext.Provider value={{ dispatch }}><ConsumerComponent /></MyContext.Provider>`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the Provider is already present but value is undefined, ensure the value prop is correctly passed: `<MyContext.Provider value={dispatch}>` (not just `value={}`)",
      "success_rate": 0.9,
      "how": "If the Provider is already present but value is undefined, ensure the value prop is correctly passed: `<MyContext.Provider value={dispatch}>` (not just `value={}`)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Wrap the component tree with the Provider: `<MyContext.Provider value={{ dispatch }}><ConsumerComponent /></MyContext.Provider>`",
    "If the Provider is already present but value is undefined, ensure the value prop is correctly passed: `<MyContext.Provider value={dispatch}>` (not just `value={}`)"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://reactjs.org/docs/context.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-04-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}