Skip to content

Commit 563b9de

Browse files
author
sw-yx
committed
move down the usememo
1 parent 6a605f8 commit 563b9de

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ dist
2323
npm-debug.log*
2424
yarn-debug.log*
2525
yarn-error.log*
26+
27+
.netlify

example/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"dependencies": {
1111
"@reach/router": "^1.2.1",
12-
"react": "^16.8.6",
12+
"react": "^15.0.0 || ^16.0.0",
1313
"react-app-polyfill": "^1.0.1",
14-
"react-dom": "^16.8.6",
14+
"react-dom": "^15.0.0 || ^16.0.0",
1515
"react-netlify-identity": "^0.1.7"
1616
},
1717
"alias": {

example/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -6212,7 +6212,7 @@ react-app-polyfill@^1.0.1:
62126212
regenerator-runtime "0.13.2"
62136213
whatwg-fetch "3.0.0"
62146214

6215-
react-dom@^16.8.6:
6215+
"react-dom@^15.0.0 || ^16.0.0":
62166216
version "16.8.6"
62176217
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
62186218
integrity sha512-1nL7PIq9LTL3fthPqwkvr2zY7phIPjYrT0jp4HjyEQrEROnw4dG41VVwi/wfoCneoleqrNX7iAD+pXebJZwrwA==
@@ -6240,7 +6240,7 @@ react-netlify-identity@^0.1.7:
62406240
gotrue-js "^0.9.25"
62416241
tsdx "^0.6.0"
62426242

6243-
react@^16.8.6:
6243+
"react@^15.0.0 || ^16.0.0":
62446244
version "16.8.6"
62456245
resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe"
62466246
integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==

src/index.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ export function IdentityContextProvider({
8787
'. Please check the docs for proper usage or file an issue.'
8888
);
8989
}
90-
const identity = React.useMemo(() => useNetlifyIdentity(url, onAuthChange), [
91-
url,
92-
onAuthChange,
93-
]);
90+
const identity = useNetlifyIdentity(url, onAuthChange);
9491
return (
9592
<_IdentityCtxProvider value={identity}>{children}</_IdentityCtxProvider>
9693
);
@@ -102,10 +99,14 @@ export function useNetlifyIdentity(
10299
onAuthChange: authChangeParam = () => {},
103100
enableRunRoutes: boolean = true
104101
): ReactNetlifyIdentityAPI {
105-
const goTrueInstance = new GoTrue({
106-
APIUrl: `${url}/.netlify/identity`,
107-
setCookie: true,
108-
});
102+
const goTrueInstance = React.useMemo(
103+
() =>
104+
new GoTrue({
105+
APIUrl: `${url}/.netlify/identity`,
106+
setCookie: true,
107+
}),
108+
[url]
109+
);
109110

110111
const [user, setUser] = React.useState<User | undefined>(
111112
goTrueInstance.currentUser() || undefined

0 commit comments

Comments
 (0)