我有一个上下文:
export const AppConstArrays = createContext({
neededHours: [],
setNeededHours: (neededHours: INeededHours[]) => { },
serviceTypes: [],
setServiceserviceTypes: (serviceTypes:IServiceTypes[]) => { },
});
我能够在数据服务中使用 set 函数,这可以正常工作。
ArraysState.setNeededHours(neededHours);
ArraysState.setServiceserviceTypes(services);
当我尝试在其他地方使用它时,
export default function reCalc(index:number) { //This is not a function component?
const ArraysState = React.useContext(AppConstArrays);
}
tslinter 没问题,但在运行时,我得到了讨厌的 321 :-)
sp-webpart-workbench-assembly_en-us_8439e1230cb8ca442df6f89cf19f89a6.js:1 Uncaught Invariant Violation: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321
Hooks can only be called inside of the body of a function component
说实话,我在任何地方都没有提供者,因为我在 .ts 文件中使用它有什么帮助吗?谢谢大家