@fluent-windows/hooks
Version:
Fluent-Windows React hooks.
26 lines (24 loc) • 577 B
JavaScript
/**
* Subscribe to mouse click events based on `onMouseUp`
*
* Demo
* import { useClick } from '@fluent-windows/hooks'
*
* function handleChange() {
* // ...
* }
* const [status, bind, setStatus] = useClick(handleChange)
*
* <div {...bind}>{status}</div>
*/
import * as React from 'react';
function useClick(statusHandler) {
const [isClicked, setClicked] = React.useState(false);
const bind = {
onMouseUp: () => {
statusHandler ? statusHandler(true) : setClicked(true);
}
};
return [isClicked, bind, setClicked];
}
export default useClick;