Skip to content

Commit 0f9b79a

Browse files
author
sw-yx
committed
change api to useIdentityContext
1 parent 02b7b61 commit 0f9b79a

File tree

13 files changed

+1452
-150
lines changed

13 files changed

+1452
-150
lines changed

README.md

+2-2
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, useN
2121
```tsx
2222
import React from "react"
2323
import "./App.css"
24-
import { useIdentityCtx, IdentityContextProvider } from "react-netlify-identity-widget"
24+
import { useIdentityContext, IdentityContextProvider } from "react-netlify-identity-widget"
2525
import "react-netlify-identity-widget/styles.css"
2626

2727
function App() {
@@ -38,7 +38,7 @@ export default App
3838
const IdentityModal = React.lazy(() => import("react-netlify-identity-widget"))
3939

4040
function AuthStatusView() {
41-
const identity = useIdentityCtx()
41+
const identity = useIdentityContext()
4242
const [dialog, setDialog] = React.useState(false)
4343
const name =
4444
(identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.name) || "NoName"

example/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@reach/dialog": "^0.2.3",
7+
"@reach/tabs": "^0.1.3",
8+
"@reach/visually-hidden": "^0.1.3",
69
"@types/jest": "24.0.11",
710
"@types/node": "11.13.8",
811
"@types/react": "16.8.14",
912
"@types/react-dom": "16.8.4",
1013
"react": "^16.8.6",
1114
"react-dom": "^16.8.6",
15+
"react-netlify-identity-widget": "^0.1.0",
1216
"react-scripts": "^3.0.0",
13-
"react-netlify-identity-widget": "latest",
14-
"typescript": "3.4.5",
15-
"@reach/dialog": "^0.2.3",
16-
"@reach/tabs": "^0.1.3",
17-
"@reach/visually-hidden": "^0.1.3"
17+
"typescript": "3.4.5"
1818
},
1919
"scripts": {
2020
"start": "react-scripts start",

example/src/App.tsx

+47-44
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
import React from "react"
22
import "./App.css"
3-
import { IdentityModal, useNetlifyIdentity, IdentityContextProvider } from "react-netlify-identity-widget"
3+
import { useIdentityContext, IdentityContextProvider } from "react-netlify-identity-widget"
44
import "react-netlify-identity-widget/styles.css"
55

6+
function App() {
7+
const url = "https://react-netlify-identity-widget.netlify.com"
8+
return (
9+
<IdentityContextProvider url={url}>
10+
<AuthStatusView />
11+
</IdentityContextProvider>
12+
)
13+
}
614

15+
// code split the modal til you need it!
16+
const IdentityModal = React.lazy(() => import("react-netlify-identity-widget"))
717

8-
function App() {
18+
function AuthStatusView() {
19+
const identity = useIdentityContext()
920
const [dialog, setDialog] = React.useState(false)
10-
const identity = useNetlifyIdentity("https://react-netlify-identity-widget.netlify.com")
1121
const name =
1222
(identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.full_name) || "NoName"
1323
const avatar_url = identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.avatar_url
1424
return (
15-
<IdentityContextProvider value={identity}>
16-
<div className="App">
17-
<header className="App-header">
18-
{identity && identity.isLoggedIn ? (
19-
<>
20-
<h1> hello {name}!</h1>
21-
{avatar_url && <img src={avatar_url} style={{ height: 100, borderRadius: "50%" }} />}
22-
<button
23-
className="btn"
24-
style={{ maxWidth: 400, background: "orangered" }}
25-
onClick={() => setDialog(true)}
26-
>
27-
LOG OUT
28-
</button>
29-
</>
30-
) : (
31-
<>
32-
<h1> hello! try logging in! </h1>
33-
<button
34-
className="btn"
35-
style={{ maxWidth: 400, background: "darkgreen" }}
36-
onClick={() => setDialog(true)}
37-
>
38-
LOG IN
39-
</button>
40-
</>
41-
)}
25+
<div className="App">
26+
<header className="App-header">
27+
{identity && identity.isLoggedIn ? (
28+
<>
29+
<h1> hello {name}!</h1>
30+
{avatar_url && <img alt="user name" src={avatar_url} style={{ height: 100, borderRadius: "50%" }} />}
31+
<button className="btn" style={{ maxWidth: 400, background: "orangered" }} onClick={() => setDialog(true)}>
32+
LOG OUT
33+
</button>
34+
</>
35+
) : (
36+
<>
37+
<h1> hello! try logging in! </h1>
38+
<button className="btn" style={{ maxWidth: 400, background: "darkgreen" }} onClick={() => setDialog(true)}>
39+
LOG IN
40+
</button>
41+
</>
42+
)}
43+
44+
<React.Suspense fallback="loading...">
4245
<IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} />
43-
<h3>
44-
Or{" "}
45-
<a
46-
href="https://github.com/sw-yx/react-netlify-identity-widget"
47-
target="_blank"
48-
style={{ color: "powderblue" }}
49-
>
50-
view the source
51-
</a>
52-
</h3>
53-
</header>
54-
</div>
55-
</IdentityContextProvider>
46+
</React.Suspense>
47+
<h3>
48+
Or{" "}
49+
<a
50+
href="https://github.com/sw-yx/react-netlify-identity-widget"
51+
target="_blank"
52+
rel="noopener noreferrer"
53+
style={{ color: "powderblue" }}
54+
>
55+
view the source
56+
</a>
57+
</h3>
58+
</header>
59+
</div>
5660
)
5761
}
58-
5962
export default App

0 commit comments

Comments
 (0)