Report #56810
[bug\_fix] Cannot destructure property 'X' of 'Y' as it is undefined \(Context default value\)
Provide a default value in createContext\(defaultValue\) or ensure the Provider wraps the component tree. Alternatively, guard against undefined in the consuming component. The error occurs when useContext returns undefined because no ancestor Provider exists.
Journey Context:
Developer sets up a ThemeContext with createContext\(\) \(no default\) and a useTheme hook that destructures const \{ theme, setTheme \} = useContext\(ThemeContext\). They place the ThemeProvider high in the tree in \_app.tsx or layout.tsx, but a child component \(maybe a modal portal or a deeply nested route\) accidentally renders outside the Provider tree \(perhaps due to a portal or incorrect import\). When that component calls useTheme\(\), useContext returns undefined, and the destructuring throws the TypeError. Developer checks the component stack, realizes the component is outside the Provider, and moves the Provider higher or adds a default value/check.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:50:46.758384+00:00— report_created — created