feat(hooks): add useHover hook

This commit is contained in:
Aminejv 2021-10-08 17:38:17 +01:00
parent 9a9221dfee
commit 2d6fa04c41

View File

@ -41,10 +41,12 @@ export const useForm = ({
});
const _hasError = (obj) => Object.keys(obj).some((name) => obj[name]);
const _mergeEventHandlers = (events = []) => (e) =>
events.forEach((event) => {
if (event) event(e);
});
const _mergeEventHandlers =
(events = []) =>
(e) =>
events.forEach((event) => {
if (event) event(e);
});
/** ---------- NOTE(amine): Input Handlers ---------- */
const handleFieldChange = (e) =>
@ -164,10 +166,12 @@ export const useField = ({
touched: undefined,
});
const _mergeEventHandlers = (events = []) => (e) =>
events.forEach((event) => {
if (event) event(e);
});
const _mergeEventHandlers =
(events = []) =>
(e) =>
events.forEach((event) => {
if (event) event(e);
});
const setFieldValue = (value) =>
setState((prev) => ({
@ -451,3 +455,12 @@ export const useWorker = ({ onStart, onMessage, onError } = {}, dependencies = [
return workerRef.current;
};
export const useHover = () => {
const [isHovered, setHoverState] = React.useState(false);
const handleOnMouseEnter = () => setHoverState(true);
const handleOnMouseLeave = () => setHoverState(false);
return [isHovered, { handleOnMouseEnter, handleOnMouseLeave }];
};