Skip to content

Commit c2a1033

Browse files
author
sw-yx
committed
add better docs and note about gatsby plugin
1 parent 8fca2b5 commit c2a1033

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

README.md

+29-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and the styles are optional but provided. here's how to use `IdentityModal, useI
2121
```tsx
2222
import React from "react"
2323
import "./App.css"
24-
import { useIdentityContext, IdentityContextProvider } from "react-netlify-identity-widget"
24+
import IdentityModal, { useIdentityContext, IdentityContextProvider } from "react-netlify-identity-widget"
2525
import "react-netlify-identity-widget/styles.css"
2626

2727
function App() {
@@ -34,31 +34,36 @@ function App() {
3434
}
3535
export default App
3636

37-
// code split the modal til you need it!
38-
const IdentityModal = React.lazy(() => import("react-netlify-identity-widget"))
39-
4037
function AuthStatusView() {
4138
const identity = useIdentityContext()
4239
const [dialog, setDialog] = React.useState(false)
4340
const name =
4441
(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+
// ...
4564
return (
4665
<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+
{/** ... */}
6267
<React.Suspense fallback="loading...">
6368
<IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} />
6469
</React.Suspense>
@@ -67,7 +72,11 @@ function AuthStatusView() {
6772
}
6873
```
6974

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
7180

7281
```bash
7382
yarn

0 commit comments

Comments
 (0)