/useFixPage

React hook for fix page

Primary LanguageTypeScript

useFixPage

A React hook to lock or unlock page. Usually used in popout scenario.

Last npm release

type

export function useFixPage(initialValue?: boolean): [boolean, React.Dispatch<React.SetStateAction<boolean>>];

install

npm install usefixpage

example

import React from 'react';
import {useFixPage} from 'usefixpage';

interface PopupPropsType {
    close: (boolean) => void;
}

const Popup: React.FC<PopupPropsType> = ({close}) => {
    return (
        <div onClick={() => close(false)}>Close</div>
    );
}

function Example() {
    const [popup, setPopup] = useFixPage(false);

    return (
        <>
            {popup ? <Popup close={setPop} /> : null}
            <div onClick={setPopup(true)}>Page</div>
        </>
    );
}