Skip to content

Commit

Permalink
Merge pull request #78 from streamich/fix-imports
Browse files Browse the repository at this point in the history
refactor: 💡 use import hooks from React proper
  • Loading branch information
streamich authored Dec 16, 2018
2 parents 5d74348 + cdc5ec5 commit c285595
Show file tree
Hide file tree
Showing 45 changed files with 57 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/__stories__/useAdopt.story.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/__stories__/useGetSet.story.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__stories__/useHoverDirty.story.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/__stories__/useOutsideClick.story.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/createMemo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useMemo} from './react';
import {useMemo} from 'react';

const createMemo = fn => (...args) => useMemo(() => fn(...args), args);

Expand Down
17 changes: 0 additions & 17 deletions src/react.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/useAsync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect, useCallback} from './react';
import {useState, useEffect, useCallback} from 'react';

export interface AsyncState<T> {
loading: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/useBattery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {on, off} from './util';

export interface BatterySensorState {
Expand Down
2 changes: 1 addition & 1 deletion src/useCounter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useGetSet from './useGetSet';
import {useCallback} from './react';
import {useCallback} from 'react';

export interface CounterActions {
inc: (delta?: number) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/useCss.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/useFavicon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect} from './react';
import {useEffect} from 'react';

const useFavicon = (href: string) => {
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useGeolocation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';

export interface GeoLocationSensorState {
accuracy: number,
Expand Down
2 changes: 1 addition & 1 deletion src/useGetSet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useRef, useCallback} from './react';
import {useRef, useCallback} from 'react';
import useUpdate from './useUpdate';

const useGetSet = <T>(initialValue: T): [() => T, (value: T) => void] => {
Expand Down
2 changes: 1 addition & 1 deletion src/useGetSetState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useRef, useCallback} from './react';
import {useRef, useCallback} from 'react';
import useUpdate from './useUpdate';

const useGetSetState = <T extends object>(initialState: T = {} as T): [() => T, (patch: Partial<T>) => void]=> {
Expand Down
3 changes: 2 additions & 1 deletion src/useHover.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import {useState} from './react';

const {useState} = React;

const noop = () => {};

Expand Down
2 changes: 1 addition & 1 deletion src/useHoverDirty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useState} from './react';
import {useEffect, useState} from 'react';

// kudos: https://usehooks.com/
const useHoverDirty = (ref) => {
Expand Down
4 changes: 2 additions & 2 deletions src/useIdle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {on, off} from './util';
import {throttle} from 'throttle-debounce';

Expand All @@ -23,7 +23,7 @@ const useIdle = (ms: number = oneMinute, initialState: boolean = false, events:
if (localState) {
set(false);
}

clearTimeout(timeout);
timeout = setTimeout(() => set(true), ms);
});
Expand Down
2 changes: 1 addition & 1 deletion src/useLifecycles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect} from './react';
import {useEffect} from 'react';

const useLifecycles = (mount, unmount?) => {
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from './react';
import {useState} from 'react';

export interface Actions<T> {
set: (list: T[]) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';

const isClient = typeof window === 'object';

Expand Down
2 changes: 1 addition & 1 deletion src/useLocation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {isClient, on, off} from './util';

const patchHistoryMethod = (method) => {
Expand Down
2 changes: 1 addition & 1 deletion src/useLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect} from './react';
import {useEffect} from 'react';
import useLifecycles from './useLifecycles';

const useLogger = (name, props) => {
Expand Down
2 changes: 1 addition & 1 deletion src/useMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from './react';
import {useState} from 'react';

export interface Actions<K, V> {
get: (key: K) => any;
Expand Down
2 changes: 1 addition & 1 deletion src/useMedia.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/useMediaDevices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {on, off} from './util';

const noop = () => {};
Expand Down
4 changes: 2 additions & 2 deletions src/useMotion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {on, off} from './util';

export interface MotionSensorState {
Expand Down Expand Up @@ -50,7 +50,7 @@ const useMotion = (initialState: MotionSensorState = defaultState) => {
rotationRate,
interval
} = event;

setState({
acceleration: {
x: acceleration.x,
Expand Down
2 changes: 1 addition & 1 deletion src/useMount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect} from './react';
import {useEffect} from 'react';

const useMount = (mount) => useEffect(mount, []);

Expand Down
2 changes: 1 addition & 1 deletion src/useNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {on, off} from './util';

export interface NetworkState {
Expand Down
6 changes: 3 additions & 3 deletions src/useObservable.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';

const useObservable = <T>(observable$, initialValue?: T): T | undefined => {
const [value, update] = useState<T | undefined>(initialValue);

useEffect(() => {
const s = observable$.subscribe(update)
return () => s.unsubscribe();
}, [observable$]);

return value;
}

Expand Down
6 changes: 3 additions & 3 deletions src/useOrientation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';
import {on, off} from './util';

export interface OrientationState {
Expand All @@ -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});
}
Expand Down
2 changes: 1 addition & 1 deletion src/useRaf.ts
Original file line number Diff line number Diff line change
@@ -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<number>(0);
Expand Down
3 changes: 2 additions & 1 deletion src/useRenderProp.ts
Original file line number Diff line number Diff line change
@@ -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<any>): [React.ReactElement<any>, any[]] => {
if (process.env.NODE_ENV !== 'production') {
if (!React.isValidElement(element)) {
Expand Down
2 changes: 1 addition & 1 deletion src/useSessionStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';

const isClient = typeof window === 'object';

Expand Down
2 changes: 1 addition & 1 deletion src/useSetState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from './react';
import {useState} from 'react';

const useSetState = <T extends object>(initialState: T = {} as T): [T, (patch: Partial<T> | Function) => void]=> {
const [state, set] = useState<T>(initialState);
Expand Down
5 changes: 3 additions & 2 deletions src/useSize.tsx
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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<HTMLIFrameElement | null>(null);
let window: Window | null = null;
Expand Down
2 changes: 1 addition & 1 deletion src/useSpeech.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useRef} from './react';
import {useRef} from 'react';
import useSetState from './useSetState';
import useMount from './useMount';

Expand Down
4 changes: 2 additions & 2 deletions src/useSpring.ts
Original file line number Diff line number Diff line change
@@ -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<Spring | null>(null);
Expand Down Expand Up @@ -32,7 +32,7 @@ const useSpring = (targetValue: number = 0, tension: number = 50, friction: numb
spring.setEndValue(targetValue);
}
}, [targetValue]);

return value;
};

Expand Down
2 changes: 1 addition & 1 deletion src/useTimeout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';

const useTimeout = (ms: number = 0) => {
const [ready, setReady] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion src/useTitle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect} from './react';
import {useEffect} from 'react';

const useTitle = (title: string) => {
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useToggle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from './react';
import {useState} from 'react';

export type UseToggle = (state: boolean) => [
boolean, // state
Expand Down
2 changes: 1 addition & 1 deletion src/useUnmount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect} from './react';
import {useEffect} from 'react';

const useUnmount = (unmount) => {
useEffect(() => () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from './react';
import {useState} from 'react';

const useUpdate = () => useState(0)[1] as (() => void);

Expand Down
2 changes: 1 addition & 1 deletion src/useWait.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Waiter, useWait } from 'react-wait'
import {Waiter, useWait} from 'react-wait';

useWait.Waiter = Waiter;

Expand Down
4 changes: 2 additions & 2 deletions src/useWindowSize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useEffect} from './react';
import {useState, useEffect} from 'react';

const isClient = typeof window === 'object';

Expand All @@ -7,7 +7,7 @@ const useWindowSize = (initialWidth = Infinity, initialHeight = Infinity) => {
width: isClient ? window.innerWidth : initialWidth,
height: isClient ? window.innerHeight : initialHeight,
});

useEffect(() => {
const handler = () => {
setState({
Expand Down
4 changes: 2 additions & 2 deletions src/util/createHTMLMediaHook.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -26,7 +26,7 @@ export interface HTMLMediaControls {
}

const createHTMLMediaHook = (tag: 'audio' | 'video') => {
const hook = (elOrProps: HTMLMediaProps | React.ReactElement<HTMLMediaProps>): [React.ReactElement<HTMLMediaProps>, HTMLMediaState, HTMLMediaControls, ReactRef<HTMLAudioElement | null>] => {
const hook = (elOrProps: HTMLMediaProps | React.ReactElement<HTMLMediaProps>): [React.ReactElement<HTMLMediaProps>, HTMLMediaState, HTMLMediaControls, {current: HTMLAudioElement | null}] => {
let element: React.ReactElement<any> | undefined;
let props: HTMLMediaProps;

Expand Down

0 comments on commit c285595

Please sign in to comment.