diff --git a/src/__stories__/useAdopt.story.tsx b/src/__stories__/useAdopt.story.tsx index cc109d3e38..874a82e1dd 100644 --- a/src/__stories__/useAdopt.story.tsx +++ b/src/__stories__/useAdopt.story.tsx @@ -1,7 +1,7 @@ import {storiesOf} from '@storybook/react'; import * as React from 'react'; import {useAdopt} from '..'; -import {useState, useCallback} from '../react'; +import {useState} from 'react'; import ShowDocs from '../util/ShowDocs'; import {Spring} from 'react-spring'; diff --git a/src/__stories__/useGetSet.story.tsx b/src/__stories__/useGetSet.story.tsx index 540a4c9cd9..3392e9af88 100644 --- a/src/__stories__/useGetSet.story.tsx +++ b/src/__stories__/useGetSet.story.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import {useGetSet} from '..'; -import {useState} from '../react'; +import {useState} from 'react'; import ShowDocs from '../util/ShowDocs'; const Demo = () => { diff --git a/src/__stories__/useHoverDirty.story.tsx b/src/__stories__/useHoverDirty.story.tsx index b784e1eeee..fc97082e44 100644 --- a/src/__stories__/useHoverDirty.story.tsx +++ b/src/__stories__/useHoverDirty.story.tsx @@ -1,6 +1,6 @@ import {storiesOf} from '@storybook/react'; import * as React from 'react'; -import {useRef} from '../react'; +import {useRef} from 'react'; import {useHoverDirty} from '..'; import ShowDocs from '../util/ShowDocs'; diff --git a/src/__stories__/useOutsideClick.story.tsx b/src/__stories__/useOutsideClick.story.tsx index 4422c02b39..27af10844d 100644 --- a/src/__stories__/useOutsideClick.story.tsx +++ b/src/__stories__/useOutsideClick.story.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import {useOutsideClick} from '..'; -import {useRef} from '../react'; +import {useRef} from 'react'; import ShowDocs from '../util/ShowDocs'; const Demo = () => { diff --git a/src/createMemo.ts b/src/createMemo.ts index 59405a81a9..fc1c43d285 100644 --- a/src/createMemo.ts +++ b/src/createMemo.ts @@ -1,4 +1,4 @@ -import {useMemo} from './react'; +import {useMemo} from 'react'; const createMemo = fn => (...args) => useMemo(() => fn(...args), args); diff --git a/src/react.ts b/src/react.ts deleted file mode 100644 index c872387a3d..0000000000 --- a/src/react.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as React from 'react'; - -export type UseState = (initialState: T | (() => T)) => [T, (newState: T | ((newState) => T)) => void]; -export const useState: UseState = (React as any).useState; - -export type UseEffect = (didUpdate: () => ((() => void) | void), params?: any[]) => void; -export const useEffect: UseEffect = (React as any).useEffect; - -export interface ReactRef {current: T}; -export type UseRef = (initialValue: T) => ReactRef; -export const useRef: UseRef = (React as any).useRef; - -export type UseCallback = any)>(callback: T, args: any[]) => T; -export const useCallback: UseCallback = (React as any).useCallback; - -export type UseMemo = (fn: Function, args: any[]) => T; -export const useMemo: UseMemo = (React as any).useMemo; diff --git a/src/useAsync.ts b/src/useAsync.ts index d35e42d738..c18df27314 100644 --- a/src/useAsync.ts +++ b/src/useAsync.ts @@ -1,4 +1,4 @@ -import {useState, useEffect, useCallback} from './react'; +import {useState, useEffect, useCallback} from 'react'; export interface AsyncState { loading: boolean; diff --git a/src/useBattery.ts b/src/useBattery.ts index a03967bc95..e699b55f63 100644 --- a/src/useBattery.ts +++ b/src/useBattery.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {on, off} from './util'; export interface BatterySensorState { diff --git a/src/useCounter.ts b/src/useCounter.ts index 1a8dcf246a..44a075bc5e 100644 --- a/src/useCounter.ts +++ b/src/useCounter.ts @@ -1,5 +1,5 @@ import useGetSet from './useGetSet'; -import {useCallback} from './react'; +import {useCallback} from 'react'; export interface CounterActions { inc: (delta?: number) => void; diff --git a/src/useCss.ts b/src/useCss.ts index 8436def921..39e7d3d32f 100644 --- a/src/useCss.ts +++ b/src/useCss.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const {create} = require('nano-css'); const {addon: addonCssom} = require('nano-css/addon/cssom'); const {addon: addonPipe} = require('nano-css/addon/pipe'); diff --git a/src/useFavicon.ts b/src/useFavicon.ts index 0ae749f4be..ee04d653c2 100644 --- a/src/useFavicon.ts +++ b/src/useFavicon.ts @@ -1,4 +1,4 @@ -import {useEffect} from './react'; +import {useEffect} from 'react'; const useFavicon = (href: string) => { useEffect(() => { diff --git a/src/useGeolocation.ts b/src/useGeolocation.ts index c935dd3fff..649cee327b 100644 --- a/src/useGeolocation.ts +++ b/src/useGeolocation.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; export interface GeoLocationSensorState { accuracy: number, diff --git a/src/useGetSet.ts b/src/useGetSet.ts index e9191c84ab..d3c8098f64 100644 --- a/src/useGetSet.ts +++ b/src/useGetSet.ts @@ -1,4 +1,4 @@ -import {useRef, useCallback} from './react'; +import {useRef, useCallback} from 'react'; import useUpdate from './useUpdate'; const useGetSet = (initialValue: T): [() => T, (value: T) => void] => { diff --git a/src/useGetSetState.ts b/src/useGetSetState.ts index 453d6cc5e6..0e0e9962d9 100644 --- a/src/useGetSetState.ts +++ b/src/useGetSetState.ts @@ -1,4 +1,4 @@ -import {useRef, useCallback} from './react'; +import {useRef, useCallback} from 'react'; import useUpdate from './useUpdate'; const useGetSetState = (initialState: T = {} as T): [() => T, (patch: Partial) => void]=> { diff --git a/src/useHover.ts b/src/useHover.ts index 16e03d5b57..06074c01ae 100644 --- a/src/useHover.ts +++ b/src/useHover.ts @@ -1,5 +1,6 @@ import * as React from 'react'; -import {useState} from './react'; + +const {useState} = React; const noop = () => {}; diff --git a/src/useHoverDirty.ts b/src/useHoverDirty.ts index 367157b6f4..e5df777d99 100644 --- a/src/useHoverDirty.ts +++ b/src/useHoverDirty.ts @@ -1,4 +1,4 @@ -import {useEffect, useState} from './react'; +import {useEffect, useState} from 'react'; // kudos: https://usehooks.com/ const useHoverDirty = (ref) => { diff --git a/src/useIdle.ts b/src/useIdle.ts index 122922753b..ac58b10ec6 100644 --- a/src/useIdle.ts +++ b/src/useIdle.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {on, off} from './util'; import {throttle} from 'throttle-debounce'; @@ -23,7 +23,7 @@ const useIdle = (ms: number = oneMinute, initialState: boolean = false, events: if (localState) { set(false); } - + clearTimeout(timeout); timeout = setTimeout(() => set(true), ms); }); diff --git a/src/useLifecycles.ts b/src/useLifecycles.ts index 841ccd4741..6db12d739b 100644 --- a/src/useLifecycles.ts +++ b/src/useLifecycles.ts @@ -1,4 +1,4 @@ -import {useEffect} from './react'; +import {useEffect} from 'react'; const useLifecycles = (mount, unmount?) => { useEffect(() => { diff --git a/src/useList.ts b/src/useList.ts index f87e54ad08..1388338db5 100644 --- a/src/useList.ts +++ b/src/useList.ts @@ -1,4 +1,4 @@ -import {useState} from './react'; +import {useState} from 'react'; export interface Actions { set: (list: T[]) => void; diff --git a/src/useLocalStorage.ts b/src/useLocalStorage.ts index 30ef2bd633..7d05e04c04 100644 --- a/src/useLocalStorage.ts +++ b/src/useLocalStorage.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const isClient = typeof window === 'object'; diff --git a/src/useLocation.ts b/src/useLocation.ts index d86481c738..9c2d242fb1 100644 --- a/src/useLocation.ts +++ b/src/useLocation.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {isClient, on, off} from './util'; const patchHistoryMethod = (method) => { diff --git a/src/useLogger.ts b/src/useLogger.ts index 6ce4d201b6..b23ab72471 100644 --- a/src/useLogger.ts +++ b/src/useLogger.ts @@ -1,4 +1,4 @@ -import {useEffect} from './react'; +import {useEffect} from 'react'; import useLifecycles from './useLifecycles'; const useLogger = (name, props) => { diff --git a/src/useMap.ts b/src/useMap.ts index 06f6ade4b5..01bad6e3f2 100644 --- a/src/useMap.ts +++ b/src/useMap.ts @@ -1,4 +1,4 @@ -import {useState} from './react'; +import {useState} from 'react'; export interface Actions { get: (key: K) => any; diff --git a/src/useMedia.ts b/src/useMedia.ts index bff87473c4..12e2331a09 100644 --- a/src/useMedia.ts +++ b/src/useMedia.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const useMedia = (query: string, defaultState: boolean = false) => { const [state, setState] = useState(defaultState); diff --git a/src/useMediaDevices.ts b/src/useMediaDevices.ts index 8df3ed11bc..c69f14d077 100644 --- a/src/useMediaDevices.ts +++ b/src/useMediaDevices.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {on, off} from './util'; const noop = () => {}; diff --git a/src/useMotion.ts b/src/useMotion.ts index 3955b64e51..a550261a9c 100644 --- a/src/useMotion.ts +++ b/src/useMotion.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {on, off} from './util'; export interface MotionSensorState { @@ -50,7 +50,7 @@ const useMotion = (initialState: MotionSensorState = defaultState) => { rotationRate, interval } = event; - + setState({ acceleration: { x: acceleration.x, diff --git a/src/useMount.ts b/src/useMount.ts index 7ff2edc4ef..eb07dcc5ce 100644 --- a/src/useMount.ts +++ b/src/useMount.ts @@ -1,4 +1,4 @@ -import {useEffect} from './react'; +import {useEffect} from 'react'; const useMount = (mount) => useEffect(mount, []); diff --git a/src/useNetwork.ts b/src/useNetwork.ts index f76850d583..77d81706bb 100644 --- a/src/useNetwork.ts +++ b/src/useNetwork.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {on, off} from './util'; export interface NetworkState { diff --git a/src/useObservable.ts b/src/useObservable.ts index 25c5821056..8aed56c28e 100644 --- a/src/useObservable.ts +++ b/src/useObservable.ts @@ -1,13 +1,13 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const useObservable = (observable$, initialValue?: T): T | undefined => { const [value, update] = useState(initialValue); - + useEffect(() => { const s = observable$.subscribe(update) return () => s.unsubscribe(); }, [observable$]); - + return value; } diff --git a/src/useOrientation.ts b/src/useOrientation.ts index 2f430bae2d..81255c1c06 100644 --- a/src/useOrientation.ts +++ b/src/useOrientation.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; import {on, off} from './util'; export interface OrientationState { @@ -20,11 +20,11 @@ const useOrientation = (initialState: OrientationState = defaultState) => { const onChange = () => { if (mounted) { const {orientation} = screen as any; - + if (!orientation) { setState(initialState); } - + const {angle, type} = orientation; setState({angle, type}); } diff --git a/src/useRaf.ts b/src/useRaf.ts index ef64d2ffce..1cefacf0b1 100644 --- a/src/useRaf.ts +++ b/src/useRaf.ts @@ -1,4 +1,4 @@ -import {useState, useLayoutEffect} from './react'; +import {useState, useLayoutEffect} from 'react'; const useRaf = (ms: number = 1e12, delay: number = 0): number => { const [elapsed, set] = useState(0); diff --git a/src/useRenderProp.ts b/src/useRenderProp.ts index 53b3444629..e16c116840 100644 --- a/src/useRenderProp.ts +++ b/src/useRenderProp.ts @@ -1,7 +1,8 @@ import * as React from 'react'; -import {useState, useCallback} from './react'; import createMemo from './createMemo'; +const {useState, useCallback} = React; + const useRenderProp = (element: React.ReactElement): [React.ReactElement, any[]] => { if (process.env.NODE_ENV !== 'production') { if (!React.isValidElement(element)) { diff --git a/src/useSessionStorage.ts b/src/useSessionStorage.ts index 615e61463c..8621bd99ec 100644 --- a/src/useSessionStorage.ts +++ b/src/useSessionStorage.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const isClient = typeof window === 'object'; diff --git a/src/useSetState.ts b/src/useSetState.ts index c5f54ce4fa..77d7274b74 100644 --- a/src/useSetState.ts +++ b/src/useSetState.ts @@ -1,4 +1,4 @@ -import {useState} from './react'; +import {useState} from 'react'; const useSetState = (initialState: T = {} as T): [T, (patch: Partial | Function) => void]=> { const [state, set] = useState(initialState); diff --git a/src/useSize.tsx b/src/useSize.tsx index c1812e0684..212083ef2f 100644 --- a/src/useSize.tsx +++ b/src/useSize.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; -import {useState, useEffect, useRef} from './react'; + +const {useState, useEffect, useRef} = React; const isClient = typeof window === 'object'; const DRAF = (callback: () => void) => setTimeout(callback, 35); @@ -25,7 +26,7 @@ const useSize = (element: Element, {width = Infinity, height = Infinity}: Partia if (typeof element === 'function') { element = element(state); } - + const style = element.props.style || {}; const ref = useRef(null); let window: Window | null = null; diff --git a/src/useSpeech.ts b/src/useSpeech.ts index a7c8a7c3b3..c4d83bdff6 100644 --- a/src/useSpeech.ts +++ b/src/useSpeech.ts @@ -1,4 +1,4 @@ -import {useRef} from './react'; +import {useRef} from 'react'; import useSetState from './useSetState'; import useMount from './useMount'; diff --git a/src/useSpring.ts b/src/useSpring.ts index 03b983fd41..d78b559002 100644 --- a/src/useSpring.ts +++ b/src/useSpring.ts @@ -1,5 +1,5 @@ import {SpringSystem, Spring} from 'rebound'; -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const useSpring = (targetValue: number = 0, tension: number = 50, friction: number = 3) => { const [spring, setSpring] = useState(null); @@ -32,7 +32,7 @@ const useSpring = (targetValue: number = 0, tension: number = 50, friction: numb spring.setEndValue(targetValue); } }, [targetValue]); - + return value; }; diff --git a/src/useTimeout.ts b/src/useTimeout.ts index 8895277104..e753060a68 100644 --- a/src/useTimeout.ts +++ b/src/useTimeout.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const useTimeout = (ms: number = 0) => { const [ready, setReady] = useState(false); diff --git a/src/useTitle.ts b/src/useTitle.ts index 84617805a6..09a0b8da67 100644 --- a/src/useTitle.ts +++ b/src/useTitle.ts @@ -1,4 +1,4 @@ -import {useEffect} from './react'; +import {useEffect} from 'react'; const useTitle = (title: string) => { useEffect(() => { diff --git a/src/useToggle.ts b/src/useToggle.ts index 77f3523e8d..3e6b1f5716 100644 --- a/src/useToggle.ts +++ b/src/useToggle.ts @@ -1,4 +1,4 @@ -import {useState} from './react'; +import {useState} from 'react'; export type UseToggle = (state: boolean) => [ boolean, // state diff --git a/src/useUnmount.ts b/src/useUnmount.ts index 415cef7f8b..69df3b5f1a 100644 --- a/src/useUnmount.ts +++ b/src/useUnmount.ts @@ -1,4 +1,4 @@ -import {useEffect} from './react'; +import {useEffect} from 'react'; const useUnmount = (unmount) => { useEffect(() => () => { diff --git a/src/useUpdate.ts b/src/useUpdate.ts index cb1948cb7b..f6212617ba 100644 --- a/src/useUpdate.ts +++ b/src/useUpdate.ts @@ -1,4 +1,4 @@ -import {useState} from './react'; +import {useState} from 'react'; const useUpdate = () => useState(0)[1] as (() => void); diff --git a/src/useWait.ts b/src/useWait.ts index ffa4c64803..92124d1039 100644 --- a/src/useWait.ts +++ b/src/useWait.ts @@ -1,4 +1,4 @@ -import { Waiter, useWait } from 'react-wait' +import {Waiter, useWait} from 'react-wait'; useWait.Waiter = Waiter; diff --git a/src/useWindowSize.ts b/src/useWindowSize.ts index 1f8f4b01fa..4f955c481f 100644 --- a/src/useWindowSize.ts +++ b/src/useWindowSize.ts @@ -1,4 +1,4 @@ -import {useState, useEffect} from './react'; +import {useState, useEffect} from 'react'; const isClient = typeof window === 'object'; @@ -7,7 +7,7 @@ const useWindowSize = (initialWidth = Infinity, initialHeight = Infinity) => { width: isClient ? window.innerWidth : initialWidth, height: isClient ? window.innerHeight : initialHeight, }); - + useEffect(() => { const handler = () => { setState({ diff --git a/src/util/createHTMLMediaHook.ts b/src/util/createHTMLMediaHook.ts index 1fbbf7eaf9..9d80b9e0d6 100644 --- a/src/util/createHTMLMediaHook.ts +++ b/src/util/createHTMLMediaHook.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import {useEffect, useRef, ReactRef} from '../react'; +import {useEffect, useRef} from 'react'; import useSetState from '../useSetState'; import parseTimeRanges from './parseTimeRanges'; @@ -26,7 +26,7 @@ export interface HTMLMediaControls { } const createHTMLMediaHook = (tag: 'audio' | 'video') => { - const hook = (elOrProps: HTMLMediaProps | React.ReactElement): [React.ReactElement, HTMLMediaState, HTMLMediaControls, ReactRef] => { + const hook = (elOrProps: HTMLMediaProps | React.ReactElement): [React.ReactElement, HTMLMediaState, HTMLMediaControls, {current: HTMLAudioElement | null}] => { let element: React.ReactElement | undefined; let props: HTMLMediaProps;