1
1
/* @flow strict-local */
2
2
import invariant from 'invariant' ;
3
- import { useRef , useEffect , useState } from 'react' ;
3
+ import * as React from 'react' ;
4
4
5
5
/**
6
6
* A Hook for the value of a prop, state, etc., from the previous render.
@@ -25,8 +25,8 @@ import { useRef, useEffect, useState } from 'react';
25
25
// (because effectively the `?` would handle it instead), and so `U` would
26
26
// be the empty type and `T | U` would be just `T`.
27
27
export function usePrevious < T , U > ( value : T , initValue : U ) : T | U {
28
- const ref = useRef < T | U > ( initValue ) ;
29
- useEffect ( ( ) => {
28
+ const ref = React . useRef < T | U > ( initValue ) ;
29
+ React . useEffect ( ( ) => {
30
30
ref . current = value ;
31
31
} ) ;
32
32
return ref . current ;
@@ -48,7 +48,7 @@ export function useDebugAssertConstant<T>(value: T) {
48
48
49
49
// Conditional, but on a per-process constant.
50
50
// eslint-disable-next-line react-hooks/rules-of-hooks
51
- const origValue = useRef ( value ) ;
51
+ const origValue = React . useRef ( value ) ;
52
52
invariant ( value === origValue . current , '' ) ;
53
53
}
54
54
@@ -71,9 +71,9 @@ export function useDebugAssertConstant<T>(value: T) {
71
71
export function useHasNotChangedForMs ( value : mixed , duration : number ) : boolean {
72
72
useDebugAssertConstant ( duration ) ;
73
73
74
- const [ result , setResult ] = useState ( false ) ;
74
+ const [ result , setResult ] = React . useState ( false ) ;
75
75
76
- useEffect ( ( ) => {
76
+ React . useEffect ( ( ) => {
77
77
setResult ( false ) ;
78
78
const id = setTimeout ( ( ) => setResult ( true ) , duration ) ;
79
79
return ( ) => clearTimeout ( id ) ;
@@ -134,4 +134,4 @@ export const useHasStayedTrueForMs = (value: boolean, duration: number): boolean
134
134
// docs could be clearer about that:
135
135
// https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects
136
136
export const useConditionalEffect = ( cb : ( ) = > void | ( ( ) => void ) , value : boolean ) : void =>
137
- useEffect ( ( ) => ( value ? cb ( ) : undefined ) , [ value , cb ] ) ;
137
+ React . useEffect ( ( ) => ( value ? cb ( ) : undefined ) , [ value , cb ] ) ;
0 commit comments