Skip to main content

Component <ClickAway />

Props

PropsTypeMeaningPossible values
handleClickAwayfunctionAction, after click did outside of the element() => void



Outside click

const ClickAwayDemo = () => {
const [isBlock, setBlock] = useState(false)

return (
<ClickAway handleClickAway={() => setBlock(false)}>
<button type="button" onClick={() => setBlock(prevOpen => !prevOpen)}>
{isBlock ? 'Hide Block' : 'Show Block'}
</button>

{isBlock && <div />}
</ClickAway>
)
}