A React hook
to lock
or unlock
page. Usually used in popout
scenario.
export function useFixPage(initialValue?: boolean): [boolean, React.Dispatch<React.SetStateAction<boolean>>];
npm install usefixpage
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>
</>
);
}