mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 17:44:50 +03:00
feat(hooks): add useHover hook
This commit is contained in:
parent
9a9221dfee
commit
2d6fa04c41
@ -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 }];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user