mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
Consistent reuse of isClient util
This commit is contained in:
parent
908f73be07
commit
94b4ea9d3e
@ -1,4 +1,5 @@
|
||||
import {useEffect} from 'react';
|
||||
import {isClient} from './util';
|
||||
|
||||
export interface ListenerType1 {
|
||||
addEventListener (name: string, handler: (event?: any) => void, ...args: any[]);
|
||||
@ -12,7 +13,7 @@ export interface ListenerType2 {
|
||||
|
||||
export type UseEventTarget = ListenerType1 | ListenerType2;
|
||||
|
||||
const defaultTarget = typeof window === 'object' ? window : null;
|
||||
const defaultTarget = isClient ? window : null;
|
||||
|
||||
const useEvent = (name: string, handler?: null | undefined | ((event?: any) => void), target: null | UseEventTarget = defaultTarget, options?: any) => {
|
||||
useEffect(() => {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {useState, useEffect} from 'react';
|
||||
|
||||
const isClient = typeof window === 'object';
|
||||
import {isClient} from './util';
|
||||
|
||||
const useLocalStorage = <T>(key: string, initialValue?: T, raw?: boolean): [T, (value: T) => void] => {
|
||||
if (!isClient) {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {useState, useEffect} from 'react';
|
||||
|
||||
const isClient = typeof window === 'object';
|
||||
import {isClient} from './util';
|
||||
|
||||
const useSessionStorage = <T>(key: string, initialValue?: T, raw?: boolean): [T, (value: T) => void] => {
|
||||
if (!isClient) {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import {isClient} from './util';
|
||||
|
||||
const {useState, useEffect, useRef} = React;
|
||||
|
||||
const isClient = typeof window === 'object';
|
||||
const DRAF = (callback: () => void) => setTimeout(callback, 35);
|
||||
|
||||
export type Element = ((state: State) => React.ReactElement<any>) | React.ReactElement<any>;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {useState, useEffect} from 'react';
|
||||
|
||||
const isClient = typeof window === 'object';
|
||||
import {isClient} from './util';
|
||||
|
||||
const useWindowSize = (initialWidth = Infinity, initialHeight = Infinity) => {
|
||||
const [state, setState] = useState<{width: number, height: number}>({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user