@@ -21,7 +21,7 @@ and the styles are optional but provided. here's how to use `IdentityModal, useI
21
21
``` tsx
22
22
import React from " react"
23
23
import " ./App.css"
24
- import { useIdentityContext , IdentityContextProvider } from " react-netlify-identity-widget"
24
+ import IdentityModal , { useIdentityContext , IdentityContextProvider } from " react-netlify-identity-widget"
25
25
import " react-netlify-identity-widget/styles.css"
26
26
27
27
function App() {
@@ -34,31 +34,36 @@ function App() {
34
34
}
35
35
export default App
36
36
37
- // code split the modal til you need it!
38
- const IdentityModal = React .lazy (() => import (" react-netlify-identity-widget" ))
39
-
40
37
function AuthStatusView() {
41
38
const identity = useIdentityContext ()
42
39
const [dialog, setDialog] = React .useState (false )
43
40
const name =
44
41
(identity && identity .user && identity .user .user_metadata && identity .user .user_metadata .name ) || " NoName"
42
+ const isLoggedIn = identity && identity .isLoggedIn
43
+ return (
44
+ <div >
45
+ <div >
46
+ <button className = " btn" onClick = { () => setDialog (true )} >
47
+ { isLoggedIn ? ` Hello ${name }, Log out here! ` : " Log In" }
48
+ </button >
49
+ </div >
50
+ <IdentityModal showDialog = { dialog } onCloseDialog = { () => setDialog (false )} />
51
+ </div >
52
+ )
53
+ }
54
+ ```
55
+
56
+ You may also code split the Modal if you wish with ` React.lazy ` and ` React.Suspense ` :
57
+
58
+ ``` js
59
+ // code split the modal til you need it!
60
+ const IdentityModal = React .lazy (() => import (" react-netlify-identity-widget" ))
61
+
62
+ function AuthStatusView () {
63
+ // ...
45
64
return (
46
65
< 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
- )}
66
+ {/** ... */ }
62
67
< React .Suspense fallback= " loading..." >
63
68
< IdentityModal showDialog= {dialog} onCloseDialog= {() => setDialog (false )} / >
64
69
< / React .Suspense >
@@ -67,7 +72,11 @@ function AuthStatusView() {
67
72
}
68
73
```
69
74
70
- # local dev
75
+ ## Gatsby plugin
76
+
77
+ You may get a little help configuring RNIW for usage with Gatsby by using https://github.com/sw-yx/gatsby-plugin-netlify-identity . Read its README for more info.
78
+
79
+ ## local dev
71
80
72
81
``` bash
73
82
yarn
0 commit comments