Component <ClickAway />
Props
Props | Type | Meaning | Possible values |
---|---|---|---|
handleClickAway | function | Action, 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>
)
}