updated prettier and eslint

This commit is contained in:
ddaza 2020-07-02 14:19:03 -05:00
parent 3f02ebf57c
commit 3ce080cdf3
49 changed files with 144 additions and 147 deletions

View File

@ -19,6 +19,7 @@
"lint": "eslint {src,tests}/**/*.{ts,tsx}",
"lint:fix": "yarn lint --fix",
"lint:types": "tsc --noEmit",
"lint:prettier":"yarn prettier --write src/**/**/*.{ts,tsx}",
"build:cjs": "tsc",
"build:es": "tsc -m esNext --outDir esm",
"build": "yarn build:cjs && yarn build:es",
@ -148,8 +149,9 @@
]
},
"lint-staged": {
"src/**/*.{ts,tsx}": [
"src/**/**/*.{ts,tsx}": [
"eslint --fix",
"prettier --write",
"git add"
]
},

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { useEffect, useState, useMemo } from 'react';
const createBreakpoint = (

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { useState } from 'react';
import useEffectOnce from './useEffectOnce';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
@ -8,7 +7,7 @@ export function createGlobalState<S = any>(initialState?: S) {
state: initialState,
setState(state: S) {
store.state = state;
store.setters.forEach(setter => setter(store.state));
store.setters.forEach((setter) => setter(store.state));
},
setters: [],
};
@ -17,7 +16,7 @@ export function createGlobalState<S = any>(initialState?: S) {
const [globalState, stateSetter] = useState<S | undefined>(store.state);
useEffectOnce(() => () => {
store.setters = store.setters.filter(setter => setter !== stateSetter);
store.setters = store.setters.filter((setter) => setter !== stateSetter);
});
useIsomorphicLayoutEffect(() => {

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { useMemo } from 'react';
const createMemo = <T extends (...args: any) => any>(fn: T) => (...args: Parameters<T>) =>

View File

@ -30,7 +30,7 @@ const createReducer = <Action, State>(...middlewares: Middleware<Action, State>[
const [, setState] = useState(ref.current);
const dispatch = useCallback(
action => {
(action) => {
ref.current = reducer(ref.current, action);
setState(ref.current);
return action;

View File

@ -1,5 +1,4 @@
/* eslint-disable */
import * as React from 'react';
import React from 'react';
export interface RouterProviderProps {
route: string;
@ -14,7 +13,7 @@ const createRouter = () => {
// not sure if this supposed to be unused, ignoring ts error for now
// @ts-ignore
const Router: React.SFC<RouterProviderProps> = props => {
const Router: React.SFC<RouterProviderProps> = (props) => {
const { route, fullRoute, parent, children } = props;
if (process.env.NODE_ENV !== 'production') {

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { DependencyList, useCallback, useState, useRef } from 'react';
import useMountedState from './useMountedState';
import { FnReturningPromise, PromiseType } from './util';
@ -40,15 +39,15 @@ export default function useAsyncFn<T extends FnReturningPromise>(
const callback = useCallback((...args: Parameters<T>): ReturnType<T> => {
const callId = ++lastCallId.current;
set(prevState => ({ ...prevState, loading: true }));
set((prevState) => ({ ...prevState, loading: true }));
return fn(...args).then(
value => {
(value) => {
isMounted() && callId === lastCallId.current && set({ value, loading: false });
return value;
},
error => {
(error) => {
isMounted() && callId === lastCallId.current && set({ error, loading: false });
return error;

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { DependencyList, useCallback, useState } from 'react';
import useAsync, { AsyncState } from './useAsync';
@ -20,7 +19,7 @@ const useAsyncRetry = <T>(fn: () => Promise<T>, deps: DependencyList = []) => {
return;
}
setAttempt(currentAttempt => currentAttempt + 1);
setAttempt((currentAttempt) => currentAttempt + 1);
}, [...deps, stateLoading]);
return { ...state, retry };

View File

@ -1,9 +1,6 @@
/* eslint-disable */
import * as React from 'react';
import { useState, useEffect } from 'react';
import { off, on, isDeepEqual } from './util';
const { useState, useEffect } = React;
export interface BatteryState {
charging: boolean;
chargingTime: number;

View File

@ -13,7 +13,7 @@ const useClickAway = <E extends Event = Event>(
savedCallback.current = onClickAway;
}, [onClickAway]);
useEffect(() => {
const handler = event => {
const handler = (event) => {
const { current: el } = ref;
el && !el.contains(event.target) && savedCallback.current(event);
};

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import writeText from 'copy-to-clipboard';
import { useCallback } from 'react';
import useMountedState from './useMountedState';
@ -18,7 +17,7 @@ const useCopyToClipboard = (): [CopyToClipboardState, (value: string) => void] =
noUserInteraction: true,
});
const copyToClipboard = useCallback(value => {
const copyToClipboard = useCallback((value) => {
if (!isMounted()) {
return;
}

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { useMemo } from 'react';
import useGetSet from './useGetSet';
import { HookState, InitialHookState, resolveHookState } from './util/resolveHookState';

View File

@ -1,7 +1,4 @@
/* eslint-disable */
import * as React from 'react';
const { useState, useMemo, useCallback, useEffect } = React;
import { useState, useMemo, useCallback, useEffect } from 'react';
export interface DropAreaState {
over: boolean;
@ -50,12 +47,12 @@ const useDrop = (options: DropAreaOptions = {}, args = []): DropAreaState => {
const process = useMemo(() => createProcess(options), [onFiles, onText, onUri]);
useEffect(() => {
const onDragOver = event => {
const onDragOver = (event) => {
event.preventDefault();
setOver(true);
};
const onDragEnter = event => {
const onDragEnter = (event) => {
event.preventDefault();
setOver(true);
};
@ -68,13 +65,13 @@ const useDrop = (options: DropAreaOptions = {}, args = []): DropAreaState => {
setOver(false);
};
const onDrop = event => {
const onDrop = (event) => {
event.preventDefault();
setOver(false);
process(event.dataTransfer, event);
};
const onPaste = event => {
const onPaste = (event) => {
process(event.clipboardData, event);
};

View File

@ -41,7 +41,7 @@ const createProcess = (options: DropAreaOptions, mounted: boolean) => (dataTrans
}
if (dataTransfer.items && dataTransfer.items.length) {
dataTransfer.items[0].getAsString(text => {
dataTransfer.items[0].getAsString((text) => {
if (mounted) {
(options.onText || noop)(text, event);
}
@ -50,23 +50,23 @@ const createProcess = (options: DropAreaOptions, mounted: boolean) => (dataTrans
};
const createBond = (process, setOver): DropAreaBond => ({
onDragOver: event => {
onDragOver: (event) => {
event.preventDefault();
},
onDragEnter: event => {
onDragEnter: (event) => {
event.preventDefault();
setOver(true);
},
onDragLeave: () => {
setOver(false);
},
onDrop: event => {
onDrop: (event) => {
event.preventDefault();
event.persist();
setOver(false);
process(event.dataTransfer, event);
},
onPaste: event => {
onPaste: (event) => {
event.persist();
process(event.clipboardData, event);
},

View File

@ -4,12 +4,11 @@ import screenfull from 'screenfull';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
export interface FullScreenOptions {
video?: RefObject<HTMLVideoElement & { webkitEnterFullscreen?: () => void; webkitExitFullscreen?: () => void; }>;
video?: RefObject<HTMLVideoElement & { webkitEnterFullscreen?: () => void; webkitExitFullscreen?: () => void }>;
onClose?: (error?: Error) => void;
}
const noop = () => {
};
const noop = () => {};
const useFullscreen = (ref: RefObject<Element>, on: boolean, options: FullScreenOptions = {}): boolean => {
const { video, onClose = noop } = options;
@ -62,8 +61,7 @@ const useFullscreen = (ref: RefObject<Element>, on: boolean, options: FullScreen
try {
screenfull.off('change', onChange);
screenfull.exit();
} catch {
}
} catch {}
} else if (video && video.current && video.current.webkitExitFullscreen) {
video.current.removeEventListener('webkitendfullscreen', onWebkitEndFullscreen);
video.current.webkitExitFullscreen();

View File

@ -45,7 +45,7 @@ const useGeolocation = (options?: PositionOptions): GeoLocationSensorState => {
}
};
const onEventError = (error: PositionError) =>
mounted && setState(oldState => ({ ...oldState, loading: false, error }));
mounted && setState((oldState) => ({ ...oldState, loading: false, error }));
useEffect(() => {
navigator.geolocation.getCurrentPosition(onEvent, onEventError, options);

View File

@ -1,27 +1,33 @@
import { useState, useCallback } from "react"
import useLifecycles from "./useLifecycles"
import { useState, useCallback } from 'react';
import useLifecycles from './useLifecycles';
/**
* read and write url hash, response to url hash change
*/
export const useHash = () => {
const [hash, setHash] = useState(() => window.location.hash)
const [hash, setHash] = useState(() => window.location.hash);
const onHashChange = useCallback(() => {
setHash(window.location.hash)
}, [])
setHash(window.location.hash);
}, []);
useLifecycles(() => {
window.addEventListener('hashchange', onHashChange)
}, () => {
window.removeEventListener('hashchange', onHashChange)
})
const _setHash = useCallback((newHash: string) => {
if (newHash !== hash) {
window.location.hash = newHash
useLifecycles(
() => {
window.addEventListener('hashchange', onHashChange);
},
() => {
window.removeEventListener('hashchange', onHashChange);
}
}, [hash])
);
return [hash, _setHash] as const
}
const _setHash = useCallback(
(newHash: string) => {
if (newHash !== hash) {
window.location.hash = newHash;
}
},
[hash]
);
return [hash, _setHash] as const;
};

View File

@ -26,7 +26,7 @@ const useKey = (key: KeyFilter, fn: Handler = noop, opts: UseKeyOptions = {}, de
const { event = 'keydown', target, options } = opts;
const useMemoHandler = useMemo(() => {
const predicate: KeyPredicate = createKeyPredicate(key);
const handler: Handler = handlerEvent => {
const handler: Handler = (handlerEvent) => {
if (predicate(handlerEvent)) {
return fn(handlerEvent);
}

View File

@ -3,8 +3,8 @@ import useKey, { KeyFilter } from './useKey';
const useKeyPress = (keyFilter: KeyFilter) => {
const [state, set] = useState<[boolean, null | KeyboardEvent]>([false, null]);
useKey(keyFilter, event => set([true, event]), { event: 'keydown' }, [state]);
useKey(keyFilter, event => set([false, event]), { event: 'keyup' }, [state]);
useKey(keyFilter, (event) => set([true, event]), { event: 'keydown' }, [state]);
useKey(keyFilter, (event) => set([false, event]), { event: 'keyup' }, [state]);
return state;
};

View File

@ -6,7 +6,7 @@ const useKeyboardJs = (combination: string | string[]) => {
const [keyboardJs, setKeyboardJs] = useState<any>(null);
useMount(() => {
import('keyboardjs').then(k => setKeyboardJs(k.default || k));
import('keyboardjs').then((k) => setKeyboardJs(k.default || k));
});
useEffect(() => {
@ -14,8 +14,8 @@ const useKeyboardJs = (combination: string | string[]) => {
return;
}
const down = event => set([true, event]);
const up = event => set([false, event]);
const down = (event) => set([true, event]);
const up = (event) => set([false, event]);
keyboardJs.bind(combination, down, up, true);
return () => {

View File

@ -1,6 +1,6 @@
import {useRef} from 'react';
import { useRef } from 'react';
const useLatest = <T>(value: T): {readonly current: T} => {
const useLatest = <T>(value: T): { readonly current: T } => {
const ref = useRef(value);
ref.current = value;
return ref;

View File

@ -99,17 +99,17 @@ function useList<T>(initialList: InitialHookState<T[]> = []): [T[], ListActions<
},
update: (predicate: (a: T, b: T) => boolean, newItem: T) => {
actions.set((curr: T[]) => curr.map(item => (predicate(item, newItem) ? newItem : item)));
actions.set((curr: T[]) => curr.map((item) => (predicate(item, newItem) ? newItem : item)));
},
updateFirst: (predicate: (a: T, b: T) => boolean, newItem: T) => {
const index = list.current.findIndex(item => predicate(item, newItem));
const index = list.current.findIndex((item) => predicate(item, newItem));
index >= 0 && actions.updateAt(index, newItem);
},
upsert: (predicate: (a: T, b: T) => boolean, newItem: T) => {
const index = list.current.findIndex(item => predicate(item, newItem));
const index = list.current.findIndex((item) => predicate(item, newItem));
index >= 0 ? actions.updateAt(index, newItem) : actions.push(newItem);
},

View File

@ -26,7 +26,7 @@ const useLocalStorage = <T>(
throw new Error('useLocalStorage key may not be falsy');
}
const deserializer = options ? (options.raw ? value => value : options.deserializer) : JSON.parse;
const deserializer = options ? (options.raw ? (value) => value : options.deserializer) : JSON.parse;
const [state, setState] = useState<T | undefined>(() => {
try {
@ -48,7 +48,7 @@ const useLocalStorage = <T>(
});
const set: Dispatch<SetStateAction<T | undefined>> = useCallback(
valOrFunc => {
(valOrFunc) => {
try {
const newState = typeof valOrFunc === 'function' ? (valOrFunc as Function)(state) : valOrFunc;
if (typeof newState === 'undefined') return;

View File

@ -2,10 +2,10 @@
import { useEffect, useState } from 'react';
import { isClient, off, on } from './util';
const patchHistoryMethod = method => {
const patchHistoryMethod = (method) => {
const original = history[method];
history[method] = function(state) {
history[method] = function (state) {
const result = original.apply(this, arguments);
const event = new Event(method.toLowerCase());

View File

@ -48,7 +48,7 @@ export default !doc
: function useLockBody(locked: boolean = true, elementRef?: RefObject<HTMLElement>) {
elementRef = elementRef || useRef(doc!.body);
const lock = body => {
const lock = (body) => {
const bodyInfo = bodies.get(body);
if (!bodyInfo) {
bodies.set(body, { counter: 1, initialOverflow: body.style.overflow });
@ -66,7 +66,7 @@ export default !doc
}
};
const unlock = body => {
const unlock = (body) => {
const bodyInfo = bodies.get(body);
if (bodyInfo) {
if (bodyInfo.counter === 1) {

View File

@ -18,7 +18,7 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
const stableActions = useMemo<StableActions<T>>(
() => ({
set: (key, entry) => {
set(prevMap => ({
set((prevMap) => ({
...prevMap,
[key]: entry,
}));
@ -26,8 +26,8 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
setAll: (newMap: T) => {
set(newMap);
},
remove: key => {
set(prevMap => {
remove: (key) => {
set((prevMap) => {
const { [key]: omit, ...rest } = prevMap;
return rest as T;
});
@ -38,7 +38,7 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
);
const utils = {
get: useCallback(key => map[key], [map]),
get: useCallback((key) => map[key], [map]),
...stableActions,
} as Actions<T>;

View File

@ -26,7 +26,7 @@ const useMeasure = <E extends HTMLElement = HTMLElement>(): UseMeasureResult<E>
const observer = useMemo(
() =>
new (window as any).ResizeObserver(entries => {
new (window as any).ResizeObserver((entries) => {
if (entries[0]) {
const { x, y, width, height, top, left, bottom, right } = entries[0].contentRect;
setRect({ x, y, width, height, top, left, bottom, right });
@ -48,4 +48,4 @@ const useMeasure = <E extends HTMLElement = HTMLElement>(): UseMeasureResult<E>
const useMeasureMock: typeof useMeasure = () => [() => {}, defaultState];
export default (isClient && !!(window as any).ResizeObserver) ? useMeasure : useMeasureMock;
export default isClient && !!(window as any).ResizeObserver ? useMeasure : useMeasureMock;

View File

@ -24,7 +24,7 @@ const useMeasureDirty = (ref: RefObject<HTMLElement>): ContentRect => {
const [observer] = useState(
() =>
new ResizeObserver(entries => {
new ResizeObserver((entries) => {
const entry = entries[0];
if (entry) {

View File

@ -12,7 +12,7 @@ const useMediaDevices = () => {
const onChange = () => {
navigator.mediaDevices
.enumerateDevices()
.then(devices => {
.then((devices) => {
if (mounted) {
setState({
devices: devices.map(({ deviceId, groupId, kind, label }) => ({ deviceId, groupId, kind, label })),

View File

@ -43,7 +43,7 @@ const useMotion = (initialState: MotionSensorState = defaultState) => {
const [state, setState] = useState(initialState);
useEffect(() => {
const handler = event => {
const handler = (event) => {
const { acceleration, accelerationIncludingGravity, rotationRate, interval } = event;
setState({

View File

@ -1,14 +1,13 @@
import {useEffect, useState} from 'react'
import { useEffect, useState } from 'react';
export default () => {
const [mouseWheelScrolled, setMouseWheelScrolled] = useState(0)
useEffect(()=>{
const updateScroll = (e : MouseWheelEvent) => {
setMouseWheelScrolled(e.deltaY + mouseWheelScrolled)
}
window.addEventListener('wheel', updateScroll, false)
return () => window.removeEventListener('wheel', updateScroll)
})
return mouseWheelScrolled
}
const [mouseWheelScrolled, setMouseWheelScrolled] = useState(0);
useEffect(() => {
const updateScroll = (e: MouseWheelEvent) => {
setMouseWheelScrolled(e.deltaY + mouseWheelScrolled);
};
window.addEventListener('wheel', updateScroll, false);
return () => window.removeEventListener('wheel', updateScroll);
});
return mouseWheelScrolled;
};

View File

@ -40,7 +40,7 @@ const useNetwork = (initialState: NetworkState = {}) => {
useEffect(() => {
let localState = state;
const localSetState = patch => {
const localSetState = (patch) => {
localState = { ...localState, ...patch };
setState(localState);
};

View File

@ -7,7 +7,7 @@ const usePageLeave = (onPageLeave, args = []) => {
return;
}
const handler = event => {
const handler = (event) => {
event = event ? event : (window.event as any);
const from = event.relatedTarget || event.toElement;
if (!from || (from as any).nodeName === 'HTML') {

View File

@ -32,7 +32,7 @@ const usePermission = (permissionDesc: PermissionDesc): State => {
useEffect(() => {
navigator.permissions
.query(permissionDesc)
.then(status => {
.then((status) => {
permissionStatus = status;
changeState();
})

View File

@ -4,7 +4,7 @@ export default function usePrevious<T>(state: T): T | undefined {
const ref = useRef<T>();
useEffect(() => {
ref.current = state
ref.current = state;
});
return ref.current;

View File

@ -9,10 +9,10 @@ const usePromise: UsePromise = () => {
return useCallback(
(promise: Promise<any>) =>
new Promise<any>((resolve, reject) => {
const onValue = value => {
const onValue = (value) => {
isMounted() && resolve(value);
};
const onError = error => {
const onError = (error) => {
isMounted() && reject(error);
};
promise.then(onValue, onError);

View File

@ -11,8 +11,8 @@ export interface QueueMethods<T> {
const useQueue = <T>(initialValue: T[] = []): QueueMethods<T> => {
const [state, set] = useState(initialValue);
return {
add: value => {
set(queue => [...queue, value]);
add: (value) => {
set((queue) => [...queue, value]);
},
remove: () => {
let result;

View File

@ -15,22 +15,28 @@ export default function useRafLoop(callback: FrameRequestCallback, initiallyActi
}
}, []);
const result = useMemo(() => ([
() => { // stop
if (rafActivity.current) {
rafActivity.current = false;
raf.current && cancelAnimationFrame(raf.current);
}
},
() => { // start
if (!rafActivity.current) {
rafActivity.current = true;
raf.current = requestAnimationFrame(step);
}
},
(): boolean => rafActivity.current // isActive
// eslint-disable-next-line react-hooks/exhaustive-deps
] as RafLoopReturns), []);
const result = useMemo(
() =>
[
() => {
// stop
if (rafActivity.current) {
rafActivity.current = false;
raf.current && cancelAnimationFrame(raf.current);
}
},
() => {
// start
if (!rafActivity.current) {
rafActivity.current = true;
raf.current = requestAnimationFrame(step);
}
},
(): boolean => rafActivity.current, // isActive
// eslint-disable-next-line react-hooks/exhaustive-deps
] as RafLoopReturns,
[]
);
useEffect(() => {
if (initiallyActive) {

View File

@ -30,7 +30,7 @@ export interface ScratchSensorState {
}
const useScratch = (params: ScratchSensorParams = {}): [(el: HTMLElement | null) => void, ScratchSensorState] => {
const {disabled} = params;
const { disabled } = params;
const paramsRef = useLatest(params);
const [state, setState] = useState<ScratchSensorState>({ isScratching: false });
const refState = useRef<ScratchSensorState>(state);
@ -49,7 +49,7 @@ const useScratch = (params: ScratchSensorParams = {}): [(el: HTMLElement | null)
const elY = top + window.scrollY;
const x = docX - elX;
const y = docY - elY;
setState(oldState => {
setState((oldState) => {
const newState = {
...oldState,
dx: x - (oldState.x || 0),
@ -64,11 +64,11 @@ const useScratch = (params: ScratchSensorParams = {}): [(el: HTMLElement | null)
});
};
const onMouseMove = event => {
const onMouseMove = (event) => {
onMoveEvent(event.pageX, event.pageY);
};
const onTouchMove = event => {
const onTouchMove = (event) => {
onMoveEvent(event.changedTouches[0].pageX, event.changedTouches[0].pageY);
};
@ -122,12 +122,12 @@ const useScratch = (params: ScratchSensorParams = {}): [(el: HTMLElement | null)
window.addEventListener('touchend', onTouchEnd);
};
const onMouseDown = event => {
const onMouseDown = (event) => {
refScratching.current = true;
startScratching(event.pageX, event.pageY);
};
const onTouchStart = event => {
const onTouchStart = (event) => {
refScratching.current = true;
startScratching(event.changedTouches[0].pageX, event.changedTouches[0].pageY);
};
@ -159,13 +159,13 @@ export interface ScratchSensorProps extends ScratchSensorParams {
children: (state: ScratchSensorState, ref: (el: HTMLElement | null) => void) => React.ReactElement<any>;
}
export const ScratchSensor: FC<ScratchSensorProps> = props => {
export const ScratchSensor: FC<ScratchSensorProps> = (props) => {
const { children, ...params } = props;
const [ref, state] = useScratch(params);
const element = render(props, state);
return cloneElement(element, {
...element.props,
ref: el => {
ref: (el) => {
if (element.props.ref) {
if (typeof element.props.ref === 'object') element.props.ref.current = el;
if (typeof element.props.ref === 'function') element.props.ref(el);

View File

@ -5,7 +5,7 @@ const getValue = (search: string, param: string) => new URLSearchParams(search).
export type UseQueryParam = (param: string) => string | null;
const useSearchParam: UseQueryParam = param => {
const useSearchParam: UseQueryParam = (param) => {
const [value, setValue] = useState<string | null>(() => getValue(location.search, param));
useEffect(() => {

View File

@ -16,12 +16,12 @@ const useSet = <K>(initialSet = new Set<K>()): [Set<K>, Actions<K>] => {
const [set, setSet] = useState(initialSet);
const stableActions = useMemo<StableActions<K>>(() => {
const add = (item: K) => setSet(prevSet => new Set([...Array.from(prevSet), item]));
const remove = (item: K) => setSet(prevSet => new Set(Array.from(prevSet).filter(i => i !== item)));
const add = (item: K) => setSet((prevSet) => new Set([...Array.from(prevSet), item]));
const remove = (item: K) => setSet((prevSet) => new Set(Array.from(prevSet).filter((i) => i !== item)));
const toggle = (item: K) =>
setSet(prevSet =>
setSet((prevSet) =>
prevSet.has(item)
? new Set(Array.from(prevSet).filter(i => i !== item))
? new Set(Array.from(prevSet).filter((i) => i !== item))
: new Set([...Array.from(prevSet), item])
);
@ -29,7 +29,7 @@ const useSet = <K>(initialSet = new Set<K>()): [Set<K>, Actions<K>] => {
}, [setSet]);
const utils = {
has: useCallback(item => set.has(item), [set]),
has: useCallback((item) => set.has(item), [set]),
...stableActions,
} as Actions<K>;

View File

@ -5,8 +5,8 @@ const useSetState = <T extends object>(
): [T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void] => {
const [state, set] = useState<T>(initialState);
const setState = useCallback(
patch => {
set(prevState => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
(patch) => {
set((prevState) => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
},
[set]
);

View File

@ -10,7 +10,7 @@ const useSpring = (targetValue: number = 0, tension: number = 50, friction: numb
// listener fn will be different on each re-render and wouldn't unsubscribe properly.
const listener = useMemo(
() => ({
onSpringUpdate: currentSpring => {
onSpringUpdate: (currentSpring) => {
const newValue = currentSpring.getCurrentValue();
setValue(newValue);
},

View File

@ -42,7 +42,7 @@ const isTypedCharGood = ({ keyCode, metaKey, ctrlKey, altKey }: KeyboardEvent) =
const useStartTyping = (onStartTyping: (event: KeyboardEvent) => void) => {
useIsomorphicLayoutEffect(() => {
const keydown = event => {
const keydown = (event) => {
!isFocusedElementEditable() && isTypedCharGood(event) && onStartTyping(event);
};

View File

@ -57,7 +57,7 @@ export function useStateWithHistory<S, I extends S>(
const setState = useCallback(
(newState: ResolvableHookState<S>): void => {
innerSetState(currentState => {
innerSetState((currentState) => {
newState = resolveHookState(newState);
// is state has changed

View File

@ -12,10 +12,10 @@ const useUnmountPromise = (): Race => {
const race = <P extends Promise<any>, E>(promise: P, onError?: (error: E) => void) => {
const newPromise: P = new Promise((resolve, reject) => {
promise.then(
result => {
(result) => {
if (!refUnmounted.current) resolve(result);
},
error => {
(error) => {
if (!refUnmounted.current) reject(error);
else if (onError) onError(error);
else console.error('useUnmountPromise', error);

View File

@ -51,7 +51,7 @@ const createHTMLMediaHook = (tag: 'audio' | 'video') => {
const ref = useRef<HTMLAudioElement | null>(null);
const wrapEvent = (userEvent, proxyEvent?) => {
return event => {
return (event) => {
try {
proxyEvent && proxyEvent(event);
} finally {

View File

@ -1,7 +1,7 @@
const defaultMapPropsToArgs = props => [props];
const defaultMapPropsToArgs = (props) => [props];
const createRenderProp = (hook, mapPropsToArgs = defaultMapPropsToArgs) => {
const RenderProp = props => {
const RenderProp = (props) => {
const state = hook(...mapPropsToArgs(props));
const { children, render = children } = props;
return render ? render(state) || null : null;

View File

@ -1,4 +1,4 @@
const parseTimeRanges = ranges => {
const parseTimeRanges = (ranges) => {
const result: { start: number; end: number }[] = [];
for (let i = 0; i < ranges.length; i++) {