小编Adi*_*san的帖子

在 next.js 中使用 context Api 和 useReducer 钩子在调用 useContext 时返回 undifined

我在 next.js 应用程序中使用 context Api 和 useReducer 钩子,当使用 contextProvider 调用 useContext 时,它会返回 undifined 。

下面是我的代码 => contextPage=>

import React, { createContext, useReducer, useContext } from 'react';
import * as types from '../constants/userConstants';

// initialized global store

export const quizContext = createContext();

// reducer

const reducer = (state, action) => {
  switch (action.type) {
    case types.USER_LOGIN_SUCCESS:
      return // user

    case types.USER_LOGOUT_SUCCESS:
      return // clear user

    default:
      return state;
  }
};

const QuizContextProvider = ({ children }) => {
  const [state, dispatch] …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js react-context

3
推荐指数
1
解决办法
3057
查看次数

标签 统计

next.js ×1

react-context ×1

reactjs ×1