Change to using arrow functions (#1603)
* Change to using arrow functions Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add lint rule --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -5,7 +5,7 @@ import { useListenClickOutside } from '../useListenClickOutside';
|
||||
|
||||
const onOutsideClick = jest.fn();
|
||||
|
||||
function TestComponentDomMode() {
|
||||
const TestComponentDomMode = () => {
|
||||
const buttonRef = useRef(null);
|
||||
const buttonRef2 = useRef(null);
|
||||
useListenClickOutside({
|
||||
@ -20,7 +20,7 @@ function TestComponentDomMode() {
|
||||
<button ref={buttonRef2}>Inside 2</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
test('useListenClickOutside hook works in dom mode', async () => {
|
||||
const { getByText } = render(<TestComponentDomMode />);
|
||||
|
||||
@ -5,7 +5,7 @@ export enum ClickOutsideMode {
|
||||
dom = 'dom',
|
||||
}
|
||||
|
||||
export function useListenClickOutside<T extends Element>({
|
||||
export const useListenClickOutside = <T extends Element>({
|
||||
refs,
|
||||
callback,
|
||||
mode = ClickOutsideMode.dom,
|
||||
@ -15,9 +15,9 @@ export function useListenClickOutside<T extends Element>({
|
||||
callback: (event: MouseEvent | TouchEvent) => void;
|
||||
mode?: ClickOutsideMode;
|
||||
enabled?: boolean;
|
||||
}) {
|
||||
}) => {
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event: MouseEvent | TouchEvent) {
|
||||
const handleClickOutside = (event: MouseEvent | TouchEvent) => {
|
||||
if (mode === ClickOutsideMode.dom) {
|
||||
const clickedOnAtLeastOneRef = refs
|
||||
.filter((ref) => !!ref.current)
|
||||
@ -61,7 +61,7 @@ export function useListenClickOutside<T extends Element>({
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (enabled) {
|
||||
document.addEventListener('click', handleClickOutside, { capture: true });
|
||||
@ -79,7 +79,7 @@ export function useListenClickOutside<T extends Element>({
|
||||
};
|
||||
}
|
||||
}, [refs, callback, mode, enabled]);
|
||||
}
|
||||
};
|
||||
export const useListenClickOutsideByClassName = ({
|
||||
classNames,
|
||||
excludeClassNames,
|
||||
|
||||
@ -2,7 +2,7 @@ import { useCallback, useEffect } from 'react';
|
||||
|
||||
type MouseListener = (positionX: number, positionY: number) => void;
|
||||
|
||||
export function useTrackPointer({
|
||||
export const useTrackPointer = ({
|
||||
shouldTrackPointer = true,
|
||||
onMouseMove,
|
||||
onMouseDown,
|
||||
@ -12,7 +12,7 @@ export function useTrackPointer({
|
||||
onMouseMove?: MouseListener;
|
||||
onMouseDown?: MouseListener;
|
||||
onMouseUp?: MouseListener;
|
||||
}) {
|
||||
}) => {
|
||||
const extractPosition = useCallback((event: MouseEvent | TouchEvent) => {
|
||||
const clientX =
|
||||
'clientX' in event ? event.clientX : event.changedTouches[0].clientX;
|
||||
@ -64,4 +64,4 @@ export function useTrackPointer({
|
||||
onInternalMouseDown,
|
||||
onInternalMouseUp,
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user