【问题标题】:useContext is undefineduseContext 未定义
【发布时间】:2021-10-28 09:08:18
【问题描述】:

我对 useContext 有疑问,因为它返回 undefined 给我。你能帮帮我吗?

Uncaught TypeError: Cannot destructure property 'course' of 'Object(...)(...)' as it is undefined.

【问题讨论】:

  • 你需要使用useContext(courseGlobal) 而不是ContextCourse 这实际上是你的Provider,而不是你的Context

标签: javascript reactjs use-context


【解决方案1】:

courseGlobal 是您的上下文。你应该将 courseGlobal 传递给 useContext 但你传递的是 ContextCourse 这是一个提供者而不是上下文

【讨论】:

    猜你喜欢
    • 2019-12-24
    • 2023-04-06
    • 2023-01-22
    • 2023-03-15
    • 2020-12-08
    • 1970-01-01
    • 2021-07-19
    相关资源
    最近更新 更多