我收到此错误(其中包括):
Type 'Dispatch<SetStateAction<null>>' is not assignable to type '() => void'
我基本上有这个:
import React, {
ReactElement,
ReactNode,
useEffect,
useRef,
useState,
useContext,
} from 'react';
export const ScrollToContext = React.createContext({
ref: React.createRef(),
setScrollTo: () => {},
});
export function useScrollTo() {
return useContext(ScrollToContext);
}
我希望上下文提供程序的值具有 2 个属性: aref和 a setScrollTo,它是一个 setState 函数。如何在 TypeScript 中输入这些内容?
如何正确初始化React.createContext,如何输入useScrollTo()返回值?
export function useScrollTo(): ??? {
return useContext(ScrollToContext);
}