浏览代码

agregando react de dependencia

Ruben Romero 3 年之前
父节点
当前提交
f0d056119a

+ 2 - 1
.gitignore

@@ -97,4 +97,5 @@ tests/cases/user/webpack/webpack
 tests/cases/user/puppeteer/puppeteer
 tests/cases/user/axios-src/axios-src
 tests/cases/user/prettier/prettier
-.eslintcache
+.eslintcache
+lib/

+ 2 - 0
package.json

@@ -14,6 +14,8 @@
   "author": "Ruben Romero <rubenxrb@gmail.com>",
   "license": "MIT",
   "devDependencies": {
+    "@types/react": "^17.0.19",
+    "react": "^17.0.2",
     "typescript": "^4.3.5"
   }
 }

+ 1 - 0
src/hooks/index.ts

@@ -1,5 +1,6 @@
 export * from "./useAlert";
 export * from "./useApp";
+export * from "./useAuth";
 export * from "./useHttp";
 export * from "./useModel";
 export * from "./useModels";

src/hooks/useAlert.ts → src/hooks/useAlert.tsx


+ 12 - 5
src/hooks/useApp.ts

@@ -1,10 +1,17 @@
 import React from "react";
 
 const localStorageKey = "usr_jwt";
-const AppContext = React.createContext();
+interface AppProviderProps {
+  type: "regular" | "firebase";
+  token: string | null;
+  setToken: (newToken: string) => void
+}
+
+const AppContext = React.createContext<AppProviderProps>({type: 'regular', token: null, setToken: () => {}});
 
-export function AppProvider(props) {
-  const [token, setToken] = React.useState(null);
+export function AppProvider(props: AppProviderProps) {
+  const [type] = React.useState(props.type);
+  const [token, setToken] = React.useState<string|null>(props.token);
 
   React.useEffect(() => {
     const jwt = localStorage.getItem(localStorageKey);
@@ -20,8 +27,8 @@ export function AppProvider(props) {
   }, [token]);
 
   const memData = React.useMemo(() => {
-    return { token, setToken };
-  }, [token, setToken]);
+    return { token, type, setToken };
+  }, [token, type, setToken]);
 
   return <AppContext.Provider value={memData} {...props} />;
 }

+ 6 - 6
src/hooks/useNotifications.ts

@@ -1,10 +1,10 @@
 import React from "react";
 
-const NotificationsContext = React.createContext();
+const AuthContext = React.createContext();
 
 // const defaultNotifications = () => [1, 2];
 
-export function NotificationsProvider(props) {
+export function AuthProvider(props) {
   const [notifications, setNotifications] = React.useState([]);
 
   // COMPONENTE SE MONTÓ
@@ -15,14 +15,14 @@ export function NotificationsProvider(props) {
     return { notifications, setNotifications };
   }, [notifications]);
 
-  return <NotificationsContext.Provider value={memData} {...props} />;
+  return <AuthContext.Provider value={memData} {...props} />;
 }
 
-export function useNotifications() {
-  const context = React.useContext(NotificationsContext);
+export function useAuth() {
+  const context = React.useContext(AuthContext);
   if (!context) {
     // eslint-disable-next-line no-throw-literal
-    throw "error: notifications context not defined.";
+    throw "error: auth context not defined.";
   }
   return context;
 }

src/hooks/useHttp.ts → src/hooks/useHttp.tsx


src/hooks/useModel.ts → src/hooks/useModel.tsx


src/hooks/useModels.ts → src/hooks/useModels.tsx


src/hooks/useNotifications.ts → src/hooks/useNotifications.tsx


src/hooks/useQuery.ts → src/hooks/useQuery.tsx


+ 1 - 1
tsconfig.json

@@ -9,7 +9,7 @@
     // "lib": [],                                   /* Specify library files to be included in the compilation. */
     // "allowJs": true,                             /* Allow javascript files to be compiled. */
     // "checkJs": true,                             /* Report errors in .js files. */
-    // "jsx": "preserve",                           /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
+    "jsx": "react",                           /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
     "declaration": true,                         /* Generates corresponding '.d.ts' file. */
     "declarationMap": true,                      /* Generates a sourcemap for each corresponding '.d.ts' file. */
     "sourceMap": true,                           /* Generates corresponding '.map' file. */

+ 49 - 0
yarn.lock

@@ -2,6 +2,55 @@
 # yarn lockfile v1
 
 
+"@types/prop-types@*":
+  version "15.7.4"
+  resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11"
+  integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==
+
+"@types/react@^17.0.19":
+  version "17.0.19"
+  resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.19.tgz#8f2a85e8180a43b57966b237d26a29481dacc991"
+  integrity sha512-sX1HisdB1/ZESixMTGnMxH9TDe8Sk709734fEQZzCV/4lSu9kJCPbo2PbTRoZM+53Pp0P10hYVyReUueGwUi4A==
+  dependencies:
+    "@types/prop-types" "*"
+    "@types/scheduler" "*"
+    csstype "^3.0.2"
+
+"@types/scheduler@*":
+  version "0.16.2"
+  resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
+  integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==
+
+csstype@^3.0.2:
+  version "3.0.8"
+  resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.8.tgz#d2266a792729fb227cd216fb572f43728e1ad340"
+  integrity sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==
+
+"js-tokens@^3.0.0 || ^4.0.0":
+  version "4.0.0"
+  resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
+  integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
+
+loose-envify@^1.1.0:
+  version "1.4.0"
+  resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
+  integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
+  dependencies:
+    js-tokens "^3.0.0 || ^4.0.0"
+
+object-assign@^4.1.1:
+  version "4.1.1"
+  resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
+  integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
+
+react@^17.0.2:
+  version "17.0.2"
+  resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
+  integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
+  dependencies:
+    loose-envify "^1.1.0"
+    object-assign "^4.1.1"
+
 typescript@^4.3.5:
   version "4.3.5"
   resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"