在函数“ header”中调用React Hook“ useStickey”

时间:2019-12-14 19:22:01

标签: reactjs react-hooks

你好,我正在尝试创建一个自定义的挂钩,但是我有这个问题,我不知道我哪里出错了,或者我是否有正确的逻辑

错误:

  

在函数“ 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))
    }
}

0 个答案:

没有答案