mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-05-03 08:36:41 +07:00
refactored react imports
This commit is contained in:
parent
a9a220273f
commit
7a7b7a4bf9
253 changed files with 679 additions and 479 deletions
src/hooks/dom
|
@ -1,4 +1,11 @@
|
|||
import React, { createContext, FC, useCallback, useContext, useEffect, useState } from 'react';
|
||||
import {
|
||||
createContext,
|
||||
FC,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
const DragContext = createContext({
|
||||
isDragging: false,
|
||||
|
@ -9,19 +16,24 @@ export const DragDetectorProvider: FC = ({ children }) => {
|
|||
const [isDragging, setIsDragging] = useState(false);
|
||||
|
||||
return (
|
||||
<DragContext.Provider value={{ isDragging, setIsDragging }}>{children}</DragContext.Provider>
|
||||
<DragContext.Provider value={{ isDragging, setIsDragging }}>
|
||||
{children}
|
||||
</DragContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useDragDetector = () => {
|
||||
const { isDragging, setIsDragging } = useContext(DragContext);
|
||||
|
||||
const onStopDragging = useCallback(() => setIsDragging(false), [setIsDragging]);
|
||||
const onStopDragging = useCallback(
|
||||
() => setIsDragging(false),
|
||||
[setIsDragging],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const addClass = () => setIsDragging(true);
|
||||
|
||||
const removeClass = event => {
|
||||
const removeClass = (event) => {
|
||||
// Small hack to ignore intersection with child elements
|
||||
if (event.pageX !== 0 && event.pageY !== 0) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue