Skip to content

Commit a2170cc

Browse files
committedJan 14, 2020
chore(types): group react imports
1 parent 2e5cdba commit a2170cc

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed
 

‎src/index.tsx

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import React from 'react';
1+
import React, {
2+
useState,
3+
useMemo,
4+
useEffect,
5+
createContext,
6+
useContext,
7+
// types
8+
Dispatch,
9+
SetStateAction,
10+
ReactNode,
11+
} from 'react';
212

313
import GoTrue, {
414
User as GoTrueUser,
@@ -27,7 +37,7 @@ const defaultSettings = {
2737
export type ReactNetlifyIdentityAPI = {
2838
user: User | undefined;
2939
/** not meant for normal use! you should mostly use one of the other exported methods to update the user instance */
30-
setUser: React.Dispatch<React.SetStateAction<User | undefined>>;
40+
setUser: Dispatch<SetStateAction<User | undefined>>;
3141
isConfirmedUser: boolean;
3242
isLoggedIn: boolean;
3343
signupUser: (
@@ -78,7 +88,7 @@ export function IdentityContextProvider({
7888
onAuthChange = () => {},
7989
}: {
8090
url: string;
81-
children: React.ReactNode;
91+
children: ReactNode;
8292
onAuthChange?: authChangeParam;
8393
}) {
8494
/******** SETUP */
@@ -102,7 +112,7 @@ export function useNetlifyIdentity(
102112
onAuthChange: authChangeParam = () => {},
103113
enableRunRoutes: boolean = true
104114
): ReactNetlifyIdentityAPI {
105-
const goTrueInstance = React.useMemo(
115+
const goTrueInstance = useMemo(
106116
() =>
107117
new GoTrue({
108118
APIUrl: `${url}/.netlify/identity`,
@@ -111,7 +121,7 @@ export function useNetlifyIdentity(
111121
[url]
112122
);
113123

114-
const [user, setUser] = React.useState<User | undefined>(
124+
const [user, setUser] = useState<User | undefined>(
115125
goTrueInstance.currentUser() || undefined
116126
);
117127
const _setUser = (_user: User | undefined) => {
@@ -120,7 +130,7 @@ export function useNetlifyIdentity(
120130
return _user; // so that we can continue chaining
121131
};
122132

123-
React.useEffect(() => {
133+
useEffect(() => {
124134
if (enableRunRoutes) {
125135
runRoutes(goTrueInstance, _setUser);
126136
}
@@ -139,8 +149,8 @@ export function useNetlifyIdentity(
139149
const acceptInviteExternalUrl = (provider: Provider, token: string) =>
140150
goTrueInstance.acceptInviteExternalUrl(provider, token);
141151
const _settings = goTrueInstance.settings.bind(goTrueInstance);
142-
const [settings, setSettings] = React.useState<Settings>(defaultSettings);
143-
React.useEffect(() => {
152+
const [settings, setSettings] = useState<Settings>(defaultSettings);
153+
useEffect(() => {
144154
_settings().then(x => setSettings(x));
145155
}, []);
146156

@@ -237,9 +247,9 @@ function validateUrl(value: string) {
237247

238248
// lazy initialize contexts without providing a Nullable type upfront
239249
function createCtx<A>() {
240-
const ctx = React.createContext<A | undefined>(undefined);
250+
const ctx = createContext<A | undefined>(undefined);
241251
function useCtx() {
242-
const c = React.useContext(ctx);
252+
const c = useContext(ctx);
243253
if (!c) throw new Error('useCtx must be inside a Provider with a value');
244254
return c;
245255
}

0 commit comments

Comments
 (0)