Invalid Hook Call. React

寵の児 提交于 2019-12-11 16:18:25

问题


I am new to React.js and I bought source code of web application. I have good experience in pure javascript. so I did all thing's and everything is working fine. except one I am getting the error shown in the ​screenshot.

import React, { useReducer } from 'react';

const initialState = {
  isOpen: false,
};

function reducer(state, action) {
  switch (action.type) {
    case 'TOGGLE':
      return {
        ...state,
        isOpen: !state.isOpen,
      };
    default:
      return state;
  }
}
export const DrawerContext = React.createContext({});

export const DrawerProvider = ({ children }) => { <-- Error
  const [state, dispatch] = useReducer(reducer, initialState);
  return (
    <DrawerContext.Provider value={{ state, dispatch }}>
      {children}
    </DrawerContext.Provider>
  );
};

来源:https://stackoverflow.com/questions/55551950/invalid-hook-call-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!