Skip to content

Commit f8dfca6

Browse files
author
sw-yx
committed
readme
1 parent 0154ce2 commit f8dfca6

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

README.md

+33-26
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,50 @@ and the styles are optional but provided. here's how to use `IdentityModal, useN
2121
```tsx
2222
import React from "react"
2323
import "./App.css"
24-
import { useNetlifyIdentity, IdentityContextProvider } from "react-netlify-identity-widget"
24+
import { useIdentityCtx, IdentityContextProvider } from "react-netlify-identity-widget"
2525
import "react-netlify-identity-widget/styles.css"
2626

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+
2737
// code split the modal til you need it!
2838
const IdentityModal = React.lazy(() => import("react-netlify-identity-widget"))
2939

30-
function App() {
40+
function AuthStatusView() {
41+
const identity = useIdentityCtx()
3142
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
3343
const name =
3444
(identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.name) || "NoName"
3545
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>
5866
)
5967
}
60-
export default App
6168
```
6269

6370
# local dev

0 commit comments

Comments
 (0)