1
- import React from 'react' ;
1
+ import React , {
2
+ useState ,
3
+ useMemo ,
4
+ useEffect ,
5
+ createContext ,
6
+ useContext ,
7
+ // types
8
+ Dispatch ,
9
+ SetStateAction ,
10
+ ReactNode ,
11
+ } from 'react' ;
2
12
3
13
import GoTrue , {
4
14
User as GoTrueUser ,
@@ -27,7 +37,7 @@ const defaultSettings = {
27
37
export type ReactNetlifyIdentityAPI = {
28
38
user : User | undefined ;
29
39
/** not meant for normal use! you should mostly use one of the other exported methods to update the user instance */
30
- setUser : React . Dispatch < React . SetStateAction < User | undefined > > ;
40
+ setUser : Dispatch < SetStateAction < User | undefined > > ;
31
41
isConfirmedUser : boolean ;
32
42
isLoggedIn : boolean ;
33
43
signupUser : (
@@ -78,7 +88,7 @@ export function IdentityContextProvider({
78
88
onAuthChange = ( ) => { } ,
79
89
} : {
80
90
url : string ;
81
- children : React . ReactNode ;
91
+ children : ReactNode ;
82
92
onAuthChange ?: authChangeParam ;
83
93
} ) {
84
94
/******** SETUP */
@@ -102,7 +112,7 @@ export function useNetlifyIdentity(
102
112
onAuthChange : authChangeParam = ( ) => { } ,
103
113
enableRunRoutes : boolean = true
104
114
) : ReactNetlifyIdentityAPI {
105
- const goTrueInstance = React . useMemo (
115
+ const goTrueInstance = useMemo (
106
116
( ) =>
107
117
new GoTrue ( {
108
118
APIUrl : `${ url } /.netlify/identity` ,
@@ -111,7 +121,7 @@ export function useNetlifyIdentity(
111
121
[ url ]
112
122
) ;
113
123
114
- const [ user , setUser ] = React . useState < User | undefined > (
124
+ const [ user , setUser ] = useState < User | undefined > (
115
125
goTrueInstance . currentUser ( ) || undefined
116
126
) ;
117
127
const _setUser = ( _user : User | undefined ) => {
@@ -120,7 +130,7 @@ export function useNetlifyIdentity(
120
130
return _user ; // so that we can continue chaining
121
131
} ;
122
132
123
- React . useEffect ( ( ) => {
133
+ useEffect ( ( ) => {
124
134
if ( enableRunRoutes ) {
125
135
runRoutes ( goTrueInstance , _setUser ) ;
126
136
}
@@ -139,8 +149,8 @@ export function useNetlifyIdentity(
139
149
const acceptInviteExternalUrl = ( provider : Provider , token : string ) =>
140
150
goTrueInstance . acceptInviteExternalUrl ( provider , token ) ;
141
151
const _settings = goTrueInstance . settings . bind ( goTrueInstance ) ;
142
- const [ settings , setSettings ] = React . useState < Settings > ( defaultSettings ) ;
143
- React . useEffect ( ( ) => {
152
+ const [ settings , setSettings ] = useState < Settings > ( defaultSettings ) ;
153
+ useEffect ( ( ) => {
144
154
_settings ( ) . then ( x => setSettings ( x ) ) ;
145
155
} , [ ] ) ;
146
156
@@ -237,9 +247,9 @@ function validateUrl(value: string) {
237
247
238
248
// lazy initialize contexts without providing a Nullable type upfront
239
249
function createCtx < A > ( ) {
240
- const ctx = React . createContext < A | undefined > ( undefined ) ;
250
+ const ctx = createContext < A | undefined > ( undefined ) ;
241
251
function useCtx ( ) {
242
- const c = React . useContext ( ctx ) ;
252
+ const c = useContext ( ctx ) ;
243
253
if ( ! c ) throw new Error ( 'useCtx must be inside a Provider with a value' ) ;
244
254
return c ;
245
255
}
0 commit comments