我是React.js的新手,我购买了Web应用程序的源代码。我在纯JavaScript方面有很好的经验。所以我做了所有事情,一切工作正常。除了一个之外,我得到了屏幕截图中显示的错误。
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>
);
};