Skip to content

Commit a20d173

Browse files
author
sw-yx
committed
readme
1 parent 61124da commit a20d173

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

README.md

+24-27
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ yarn add react-netlify-identity
3232

3333
## Usage
3434

35+
⚠️ **Important:** You will need to have an active Netlify site running with Netlify Identity turned on. [Click here for instructions](https://www.netlify.com/docs/identity/#getting-started) to get started/double check that it is on. We will need your site's url (e.g. `https://mysite.netlify.com`) to initialize `useNetlifyIdentity`.
36+
3537
**As a React Hook**, you can destructure these variables and methods:
3638

3739
- `user: User`
@@ -47,38 +49,39 @@ yarn add react-netlify-identity
4749
- `getFreshJWT()`
4850
- `authedFetch(endpoint: string, obj = {})` (a thin axios-like wrapper over `fetch` that has the user's JWT attached, for convenience pinging Netlify Functions with Netlify Identity)
4951

50-
<details>
51-
<summary>
52-
<h3 style="color: red">
53-
Click to See Example code
54-
</h3>
55-
</summary>
56-
5752
```tsx
5853
import * as React from 'react';
5954

6055
import { useNetlifyIdentity } from 'react-netlify-identity';
6156

6257
const IdentityContext = React.createContext(); // not necessary but recommended
6358
function App() {
64-
const identity = useNetlifyIdentity(url);
59+
const identity = useNetlifyIdentity(url); // supply the url of your Netlify site instance. VERY IMPORTANT
6560
return (
6661
<IdentityContext.Provider value={identity}>
6762
{/* rest of your app */}
6863
</IdentityContext.Provider>
6964
);
7065
}
66+
```
67+
68+
<details>
69+
<summary>
70+
<h3 style="color: red">
71+
Click for More Example code
72+
</h3>
73+
</summary>
7174

75+
```tsx
7276
// log in/sign up example
7377
function Login() {
7478
const { loginUser, signupUser } = React.useContext(IdentityContext);
7579
const formRef = React.useRef();
7680
const [msg, setMsg] = React.useState('');
77-
const [isLoading, load] = useLoading();
7881
const signup = () => {
7982
const email = formRef.current.email.value;
8083
const password = formRef.current.password.value;
81-
load(signupUser(email, password))
84+
signupUser(email, password)
8285
.then(user => {
8386
console.log('Success! Signed up', user);
8487
navigate('/dashboard');
@@ -112,15 +115,11 @@ function Login() {
112115
<input type="password" name="password" />
113116
</label>
114117
</div>
115-
{isLoading ? (
116-
<Spinner />
117-
) : (
118-
<div>
119-
<input type="submit" value="Log in" />
120-
<button onClick={signup}>Sign Up </button>
121-
{msg && <pre>{msg}</pre>}
122-
</div>
123-
)}
118+
<div>
119+
<input type="submit" value="Log in" />
120+
<button onClick={signup}>Sign Up </button>
121+
{msg && <pre>{msg}</pre>}
122+
</div>
124123
</form>
125124
);
126125
}
@@ -149,12 +148,10 @@ function PrivateRoute(props) {
149148
// use authedFetch API to make a request to Netlify Function with the user's JWT token,
150149
// letting your function use the `user` object
151150
function Dashboard() {
152-
const props = React.useContext(IdentityContext);
153-
const { isConfirmedUser, authedFetch } = props;
154-
const [isLoading, load] = useLoading();
151+
const { isConfirmedUser, authedFetch } = React.useContext(IdentityContext);
155152
const [msg, setMsg] = React.useState('Click to load something');
156153
const handler = () => {
157-
load(authedFetch.get('/.netlify/functions/authEndPoint')).then(setMsg);
154+
authedFetch.get('/.netlify/functions/authEndPoint').then(setMsg);
158155
};
159156
return (
160157
<div>
@@ -172,14 +169,16 @@ function Dashboard() {
172169
If you are logged in, you should be able to see a `user` info here.
173170
</p>
174171
<button onClick={handler}>Ping authenticated API</button>
175-
{isLoading ? <Spinner /> : <pre>{JSON.stringify(msg, null, 2)}</pre>}
172+
<pre>{JSON.stringify(msg, null, 2)}</pre>
176173
</div>
177174
</div>
178175
);
179176
}
180177
```
181178

182-
This is also exported as a render prop component, `NetlifyIdentity`, but we're not quite sure if its that useful if you can already use hooks:
179+
</details>
180+
181+
**As a render prop**: This is also exported as a render prop component, `NetlifyIdentity`, but we're not quite sure if its that useful if you can already use hooks in your app:
183182

184183
```tsx
185184
<NetlifyIdentity domain="https://mydomain.netlify.com">
@@ -189,8 +188,6 @@ This is also exported as a render prop component, `NetlifyIdentity`, but we're n
189188
</NetlifyIdentity>
190189
```
191190

192-
</details>
193-
194191
## License
195192

196193
MIT © [sw-yx](https://github.com/sw-yx)

0 commit comments

Comments
 (0)