Skip to content

Commit

Permalink
feat: import utility functions from @tonic-ui/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Nov 15, 2023
1 parent 28da282 commit c8681c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
12 changes: 1 addition & 11 deletions packages/react-hooks/src/useEventListener.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { noop, runIfFn } from '@tonic-ui/utils';
import { useEffect } from 'react';
import useEventCallback from './useEventCallback';

// TODO: move to '@tonic-ui/utils'
const noop = () => {};

// TODO: move to '@tonic-ui/utils'
const runIfFn = (valueOrFn, ...args) => {
if (typeof valueOrFn === 'function') {
return valueOrFn(...args);
}
return valueOrFn;
};

/**
* A custom Hook to manage browser event listeners.
*
Expand Down
4 changes: 1 addition & 3 deletions packages/react-hooks/src/useMediaQuery.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { noop } from '@tonic-ui/utils';
import { useEffect, useState } from 'react';

// TODO: move to '@tonic-ui/utils'
const noop = () => {};

const getInitialState = (query, defaultValue) => {
if (defaultValue !== undefined) {
return defaultValue;
Expand Down
9 changes: 2 additions & 7 deletions packages/react-hooks/src/useOutsideClick.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { getOwnerDocument, noop } from '@tonic-ui/utils';
import { useEffect } from 'react';
import useEventCallback from './useEventCallback';

// TODO: move to '@tonic-ui/utils'
const noop = () => {};

// TODO: move to '@tonic-ui/utils'
const ownerDocument = (node) => (node?.ownerDocument || document);

const defaultEvents = ['mousedown', 'touchstart'];

/**
Expand All @@ -33,7 +28,7 @@ const useOutsideClick = (

const filteredEvents = (Array.isArray(events) ? events : [])
.filter(x => (typeof x === 'string'));
const doc = ownerDocument(ref?.current);
const doc = getOwnerDocument(ref?.current);

for (const eventName of filteredEvents) {
doc?.addEventListener?.(eventName, savedHandler, true);
Expand Down

0 comments on commit c8681c6

Please sign in to comment.