【问题标题】:React Private Route and hooks context and reducerReact Private Route 和 hooks context 和 reducer
【发布时间】:2020-06-06 17:42:10
【问题描述】:

我尝试使用私有路由实现 Auth,并使用 useReducer 和 Context 实现 Hooks。当我在仪表板尝试 ti route 时出现错误

Cannot read property 'isAuthenticated' of undefined

为什么?我在 stackblitz 上的代码。 https://stackblitz.com/edit/react-caertn

你能帮帮我吗? 太感谢了。 马可.意大利

【问题讨论】:

    标签: reactjs react-router react-hooks


    【解决方案1】:

    您正在混合 Provider/Consumer 和 Hook 组件。这是一个更新的示例,它引入了 useAuth 钩子。

    https://stackblitz.com/edit/react-fqsfpn

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2021-06-25
      • 2021-06-03
      • 2019-04-01
      • 1970-01-01
      • 2021-10-11
      相关资源
      最近更新 更多