@@ -21,43 +21,50 @@ and the styles are optional but provided. here's how to use `IdentityModal, useN
21
21
``` tsx
22
22
import React from " react"
23
23
import " ./App.css"
24
- import { useNetlifyIdentity , IdentityContextProvider } from " react-netlify-identity-widget"
24
+ import { useIdentityCtx , IdentityContextProvider } from " react-netlify-identity-widget"
25
25
import " react-netlify-identity-widget/styles.css"
26
26
27
+ function App() {
28
+ const url = process .env .REACT_APP_NETLIFY_URL // supply the url of your Netlify site instance. VERY IMPORTANT
29
+ return (
30
+ <IdentityContextProvider value = { identity } >
31
+ <AuthStatusView />
32
+ </IdentityContextProvider >
33
+ )
34
+ }
35
+ export default App
36
+
27
37
// code split the modal til you need it!
28
38
const IdentityModal = React .lazy (() => import (" react-netlify-identity-widget" ))
29
39
30
- function App() {
40
+ function AuthStatusView() {
41
+ const identity = useIdentityCtx ()
31
42
const [dialog, setDialog] = React .useState (false )
32
- const url = process .env .REACT_APP_NETLIFY_URL // supply the url of your Netlify site instance. VERY IMPORTANT
33
43
const name =
34
44
(identity && identity .user && identity .user .user_metadata && identity .user .user_metadata .name ) || " NoName"
35
45
return (
36
- <IdentityContextProvider value = { identity } >
37
- <div className = " App" >
38
- { identity && identity .isLoggedIn ? (
39
- <header className = " App-header" >
40
- <h1 > hello { name } !</h1 >
41
- <button className = " btn" onClick = { () => setDialog (true )} >
42
- LOG OUT
43
- </button >
44
- </header >
45
- ) : (
46
- <header className = " App-header" >
47
- <h1 > hello! try logging in! </h1 >
48
- <button className = " btn" onClick = { () => setDialog (true )} >
49
- LOG IN
50
- </button >
51
- </header >
52
- )}
53
- <React.Suspense fallback = " loading..." >
54
- <IdentityModal showDialog = { dialog } onCloseDialog = { () => setDialog (false )} />
55
- </React.Suspense >
56
- </div >
57
- </IdentityContextProvider >
46
+ <div className = " App" >
47
+ { identity && identity .isLoggedIn ? (
48
+ <header className = " App-header" >
49
+ <h1 > hello { name } !</h1 >
50
+ <button className = " btn" onClick = { () => setDialog (true )} >
51
+ LOG OUT
52
+ </button >
53
+ </header >
54
+ ) : (
55
+ <header className = " App-header" >
56
+ <h1 > hello! try logging in! </h1 >
57
+ <button className = " btn" onClick = { () => setDialog (true )} >
58
+ LOG IN
59
+ </button >
60
+ </header >
61
+ )}
62
+ <React.Suspense fallback = " loading..." >
63
+ <IdentityModal showDialog = { dialog } onCloseDialog = { () => setDialog (false )} />
64
+ </React.Suspense >
65
+ </div >
58
66
)
59
67
}
60
- export default App
61
68
```
62
69
63
70
# local dev
0 commit comments