你好,我正在尝试创建一个自定义的挂钩,但是我有这个问题,我不知道我哪里出错了,或者我是否有正确的逻辑
错误:
在函数“ header”中调用“ React Hook”“ useStickey” 既不是React函数组件也不是自定义的React Hook函数
const header = () => {
const {menuFixed,overlayFixed,overlayRect,stickOverlay,stickTopMenu,unStickOverlay,unStickTopMenu,handleOverlayRef} = useStickey();
return(<></>)}
我的自定义钩子:
import React, { useState, useEffect,useRef, useCallback } from 'react';
export const useStickey = () => {
const [menuFixed, setMenuFixed] = useState(false);
const [overlayFixed, setOverlayFixed] = useState(false);
const [ overlayRect, setOverlayRect] = useState(null);
return {
menuFixed,setMenuFixed,
overlayFixed,setOverlayFixed,
overlayRect,setOverlayRect,
stickOverlay: useCallback(setOverlayFixed(true)),
stickTopMenu: useCallback(setMenuFixed(true)),
unStickOverlay: useCallback(setOverlayFixed(false)),
unStickTopMenu: useCallback(setMenuFixed(false)),
handleOverlayRef: useCallback( value => setOverlayRect(value))
}
}